Spread pesto over one side of the bread. Top with Swiss cheese. Cover the cheese completely with ham.
Heat a skillet over medium-high heat. Add sandwich ham-side down; cook until ham starts to caramelize and cheese begins to melt, 3 to 4 minutes. Spread 1 tablespoon butter carefully over the top side of the bread. Flip and cook sandwich until buttered side is golden brown, 3 to 4 minutes.
Meanwhile, melt butter in another skillet. Crack egg into the hot butter and fry until white is set, 3 to 5 minutes. Transfer sandwich to a plate and top with the fried egg.