in reply to Re: Why does default $_ only work
in thread Why does default $_ only work

Your problem has nothing to do with chomp, but rather the syntax of the match. Refer to the section "Regexp Quote-Like Operators" in perlop.
use strict; use warnings; my $secret = \"AA"; close STDIN; open STDIN, '<', $secret or die $!; print "Enter a string that will match the secret matching pattern \n"; chomp (my $selection = <STDIN>); if ($selection =~ m/(.)\1/) { print "The match was perfect \n"; } else { print "Match not found \n"; }

OUTPUT:

Enter a string that will match the secret matching pattern The match was perfect

Note that you first example only appears to "work". It gets the right answer for the wrong reason.

Bill