local($^I, @ARGV) = ('.bak', 'file.txt'); while (<> ) { if ($. == 5) { $line5 = $_; print "his is the 5th line !\n"; next; } print; close ARGV if eof; # Reset $. } </pre><HR></BLOCKQUOTE> If you are doing this inside a block of code you want to do other stuf in undefine $^I line this undef $^I