in reply to Exec'ing a regex stored in a scalar variable

my @regexs; !/^\s*$/ and push @regexs, $_ while <DATA>; my @smth = ("test_for r1", "+ test_for_r2 +"); $_ = eval for @regexs; for my $string (@smth){ for(@regexs){ $string =~ /$_/ and print "pattern \"$_\" is ok for \"$string\"$/" } } # STDOUT: # pattern "(?i-xsm:^\w+\s+\w+$)" is ok for "test_for r1" # pattern "(?i-xsm:^\W+\w+\W+$)" is ok for "+ test_for_r2 +" __DATA__ qr{^\w+\s+\w+$}i qr{^\W+\w+\W+$}i