use strict; use warnings; my $tempfile = "temp.txt"; my $origfile = "guestbook.txt"; my $prepend_text = "Stuff to prepend...\n"; open TEMP, ">$tempfile" or die "Can't create temp file. $!\n"; print TEMP $prepend_text; open ORIG, "<$origfile" or die "Can't read guestbook file. $!\n"; while ( my $line = ) { print TEMP $line; } close ORIG; close TEMP or die "Unable to close output file: $!\n"; rename $tempfile, $origfile; #### use strict; use warnings; use Tie::File; my $string = "Text to be prepended.\n"; my @array; { my $obj = tie @array, 'Tie::File', "guestbook.txt" or die "Can't open the guestbook file. $!\n"; $obj->flock; unshift @array, $string; untie @array; }