use CGI qw(:standard); my $file = 'foo.txt'; my $lines = read_file($file); print header(), start_form(), textarea( -name => 'head', -value => $lines, -rows => 6, -cols => 60, -wrap => 'soft', -override => 1, ), p(submit()); my $head = strip(param('head')); print end_form(); if ($head) { write_file($file,$head); } sub read_file { my $file = shift; open(FILE,$file) or die "$file not readable: $!"; my @lines = ; close(FILE); return join('',@lines); } sub write_file { my ($file,$new_head) = @_; print STDERR "adding $new_head"; open (FILE,'>',$file) or die "$file not writeable"; flock (FILE, 2) or die "$file not lockable"; print FILE $new_head; close(FILE); } sub strip { my $param = shift; return '' unless $param; $param =~ s/^\s+//g; $param =~ s/\s+$//g; return $param; }