#!/usr/bin/perl use strict; use Fcntl qw(:flock :seek); my $stuff_from_myform = 'something to add'; my $MyFile = "$0.zzz"; open MYFILE, "+< $MyFile" or die "Cannot Open $MyFile: $!"; flock MYFILE, LOCK_EX or die "Unable to acquire exclusive lock for $MyFile: $!"; my @data = ( , "$stuff_from_myform\n" ); shift @data while @data > 10; #limit to 10 lines seek MYFILE, 0, SEEK_SET; truncate MYFILE, 0; print MYFILE @data; close MYFILE;