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

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

Here is a text file containing data I need to munge:
"ADELMAN","John","adad","Ray" "AGAN","John","agag","Aditya" "AHMED","John","ahah","Conor"
Here is a perl script to do some munging:
my $username; my $color; while(<>){ chomp; s/"//g; ($username,$color) = (split /,/,$_)[2,3]; if ("agag" =~ m/($username)/){print STDOUT "here is the username: +$username\n"} }
Here is the output when I invoke perl test.pl test.txt at the command line:
here is the username:
so note what's happening here: Evidently, the interpolation of the variable $username works just fine in the match "agag" =~ m/($username)/. But then, $username get's treated as empty (uninitialized?) inside the call to print. I'm totally stumped. please help.