in reply to rearrange lines in file

ZxCv,
Might I suggest using Tie::File for this task. Basically, it allows you to treat a file like a Perl array. It should be straight forward then to read forward and backward from the array and writing to the file.

Cheers - L~R

Update: You don't even need to write code to read the array if you make a copy of the original file. You can just use pop and shift to create the new file. This will leave the original file empty unless you have copied it first. If you do not want to copy the file, then you will have to write your own logic.