use strict; use warnings; print "Gimme a string: "; my $str = ; chomp $str; print "Gimme a RegEx: "; my $pattern = ; chomp $pattern; my $rex; { # a block to localize $@ local $@; # eval the regex eval{ $rex = qr/$pattern/ }; # die if errors die "error compiling regex!" if $@; } # end of the localizing block print $str =~ /$rex/ ? "Yes!" : "No.";