#file: test.pl #!/usr/bin/perl -w use strict; my $pattern='test'; my $output='$&'; while() { chomp; my $line=$_; chomp($line); $line=~/$pattern/; #print "$line:".$'."\n"; #why uncommenting this line make the following line pass without no warning. my $result="$line:".eval($output)."\n"; print $result; } __DATA__ test1a.txt test1b.txt test1c.txt