in reply to Using seek function to write out to top of file?

seek is not the tool I would choose for this task, but if I had to use it, I'd do this:

open my $fh, '+<cat.txt' or die $!; my $text = do { local $/; <$fh> }; # slurp die "seek failed\n" unless seek( $fh, 0, SEEK_SET ); print $fh "The\n$text"; close $fh;
If one seeks and then just writes "The\n", some of the original contents of the file will get overwritten. Therefore one has to first save these contents, and write them back out. See seek.

Updates: fixed typo: s/<\+/+</ ; added check on seek's success; replaced 0 with SEEK_SET as the third argument of seek.

the lowliest monk