in reply to Re: Making sure user input is a valid regexp
in thread Making sure user input is a valid regexp

And in print, you would use $error instead of $! replaced by $@ :)