my $re_str=qr{([0-6BS])}; $_="B"; my $ans; if (eval m{$re_str}) #### my $re_str="qr{([0-6BS])}"; $_="B"; my $ans; if (eval m{$re_str}) #### #not tested, YMMV for $key (keys %options) { if ($key =~ s/^#//) { if (/$key/) { print "Match: $1\n"; } } else } if ($_ eq $key) { print "Equals: $1\n"; } } }