in reply to Regex Start Anchor with variables
However, if you really want to use a regular expression then you need to escape the meta-characters in $str2:if ( 0 == index $str1, $str2 ) { print "match\n"; } else { print "nomatch\n"; }
if( $str1 =~ /^\Q$str2/ ) { print "match\n"; } else { print "nomatch\n"; }
|
|---|