perl -i -ne 'print if $.-1' file perl -i -pe 'goto LINE if $. == 1' file perl -i -pe '$_=$+if!$if++' file