in reply to Re^2: Inserting a line in the middle of a text
in thread Inserting a line in the middle of a text

There are some advantages to working in-place over creating a temporary file:

This is pretty close to what the -i commandline switch does for Perl one liners

-i is closer to

open(my $fh_in, '<', $qfn); unlink($qfn); open(my $fh_out, '>', $qfn); ...

for now.