in reply to Executing a "/foo/flags" regex from a string

qr can do it as perlre syntax allows (?i) the same as /i

$ perl -le " print int q{shoes} =~ /SHOES/ " 0 $ perl -le " print int q{shoes} =~ /SHOES/i " 1 $ perl -le " print int q{shoes} =~ /(?i)SHOES/ " 1

App::Ack uses this trick

You can use eval { no re qw/eval/; qr/$regex/ }; to see if the regex compiles

See also Text::Glob#glob_to_regex