in reply to Writing infront of the file

Here is how I would do it:

my $file = "/foo/bar.txt"; open(FOO, "+< $file") or die qq[Could not open "$file": $!\n]; @slurp = <FOO>; seek(FOO, 0, 0); print FOO "I am at the very start of the file!\n"; print FOO @slurp; truncate(FOO, tell(FOO)); close(FOO);