in reply to System command problem in perl

You don't need to run perl through system, you can do that directly in perl:

#!/usr/bin/perl use strict; use warnings; { local ( $^I, @ARGV ) = ( '', 'test.txt' ); while ( <> ) { s/#//; print; } } { local ( $^I, @ARGV ) = ( '', 'test.txt' ); while ( <> ) { s/(?=.*\btest\b)/#/; print; } }