$ cat 2 1 2 3 4 $ perl -i.orig -p -l -e "print 'three' if /3/" 2 $ cat 2 1 2 three 3 4 $ cat 2.orig 1 2 3 4 $ perl -MO=Deparse -i.orig -p -l -e "print 'three' if /3/" BEGIN { $^I = ".orig"; } BEGIN { $/ = "\n"; $\ = "\n"; } LINE: while (defined($_ = )) { chomp $_; print 'three' if /3/; } continue { print $_; } -e syntax OK