in reply to Pattern mattching
Note that the s flag is for substitution. What you want is a match, so the s is left out. Also, as people have stated above, $a is a reserved variable, and while you can use it for this, you probably shouldn't. Also, as stated above, your regex can be shortened:my $c = '+000000'; print 'contains' if $c =~ /\+\d\d\d\d\d\d/;
And if you need to match exactly:my $c = '+000000'; print 'contains' if $c =~ /\+\d{6}/;
my $c = '+000000'; print 'contains' if $c =~ /^\+\d{6}$/; # or... print 'contains' if $c eq '+'.'0'x6;
|
|---|