use Fcntl qw(:seek :flock); # get constants # location suitable for direct use in seek. use constant INSERT_LOCATION => (-947, SEEK_END); my $file = "..."; # open the file for update open FILE, "+<$file" or die "couldn't open $file: $!\n"; # don't have two copies of us update the file at the # same time... flock FILE, LOCK_EX or die "flock: $!\n"; # go to our location seek FILE, INSERT_LOCATION or die "seek: $!\n"; # read the rest of the file from there my $end = do { local $/; }; defined $end or die "read: $!\n"; # go back to our location seek FILE, INSERT_LOCATION or die "seek: $!\n"; # write new data followed by old data from that point. print FILE $newlines, $end or die "print: $!\n"; close FILE or warn "close: $!\n";