in reply to print lines from a file

Actually you can read, write, append at the the same time ( perldoc -f open modes ).
But the problem is the operating system which will not allow you to write at the beginning,
though you can read from any place in some modes.
It can be quite easy without simultaneous read/write:
use strict; my $lines = 10; my $file_r = "from_filename"; my $file_w = "to_filename"; my (@_1, @_2); open FH, $file_r or die $!; $. > $lines and push @_1, $_ or push @_2, $_ while <FH>; close FH; open FH1, "> $file_r" or die $!; open FH2, "> $file_w" or die $!; print FH1 $_ for @_1; print FH2 $_ for @_2;