in reply to Writing infront of the file

That would be one of the perlfaq entries.

-- Randal L. Schwartz, Perl hacker