Hi chrism01, use Quotemeta "\Q & \E".
if( $str1 =~ /^\Q$str2\E/ ) { print "match\n"; } else { print "nomatch\n"; }
Updated
See the documentation in perldoc as quotemeta
In string2 $str2 = ".1.2.3.4";, dots(.) are present and it will be treated as any character except new line in regular expression. So dots should be escaped using "\Q".
Regards,
Velusamy R.
In reply to Re: Regex Start Anchor with variables
by Samy_rio
in thread Regex Start Anchor with variables
by chrism01
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |