http://qs321.pair.com?node_id=873611


in reply to Re^2: find & replace a string in perl
in thread find & replace a string in perl

The code:
if( $line =~ s/\btest\b/^\#/ig ) { print "$line\n"; }
is definately wrong as Corion has been saying.
The bit in brackets after the "if" should be a test with a Boolean answer, whereas you've got a substitute command instead. Also if the substitution ever worked you would not be adding a hash in front of the line but replacing "test" with "^#" so your example line "see/for/test " would become "see/for/^#". You want something like:
if( $line =~ m/test/ ) { $line = "#" . $line; print "$line\n"; }