http://www.perlmonks.org?node_id=102519

jalebie has asked for the wisdom of the Perl Monks concerning the following question:

For some reason this code doesn't seem to match properly even though both the variables are the same.
use strict; my $var1 = "a+b"; my $var2 = "a+b"; if ($var1 =~ /$var2/) { print "hey it matches \n"; } print "hey here \n";
I know that the + is a special metacharacter, and have even tried making $var2 = "a\+b" but for some reason this doesnt work for me either. The only thing that works is when i have 2 forward slashes before the + character like this. $var2 = "a\\+b"; I cannot figure out a logical reason for this. Please if anyone can help me, This is actually a part of a bigger program that is failing when it sees the + character Waris