in reply to Print all lines in a file except the last two

another idea...
If you don't want the last two lines you could truncate them
open(F, '+<afile.txt') || die 'cannot open afile.txt'; while (<F>) { push(@addrs, tell(F)) unless eof(F); } truncate(F, $addrs[-2]) || die 'cannot truncate afile.txt';
This will remove the last two lines in a file.
I got the idea for this in the Perl Cookbook. Recipe 8.10
If you don't have that book I recommend it.