if( $line =~ s/\btest\b/^\#/ig ) { print "$line\n"; } #### if( $line =~ m/test/ ) { $line = "#" . $line; print "$line\n"; }