The filehandle is ARGV. While -i
may raise questions about seeking, it works in my tests
perl -i.bak -pe'
$_ = "line: $_";
if ($. == 2) { seek ARGV, 0, 0 }
' test.txt
If you see issues with -i
or the backup (I don't) run without them and do that manually.
With the -p
switch the $_
is printed every time through. Code shown in the comment uses it but the question seems to imply that not every line need be printed, as it wants to "remove entries" from the beginning. If that is the case then use -n
instead of -p
, which also opens the file and iterates over its lines but does not print. Then add print statements as needed.
It is generally a very good idea to read I/O Operators in perlop, and once you are mucking about with this I'd really recommend it.
It appears that there may be better approaches for your problem but we'd need more detail.