in reply to Stopping bad input (harder than sanitizing)

Your immediate problem is simple: sub search goes into an infinite loop if $search_pattern is undefined. Instead of a goto, simply return early, as in return unless defined $search_pattern; which will cause the Tk event loop to resume and the UI to wait for the user to try again.