#!/usr/local/bin/perl use strict; use CGI qw(:all); my $file = 'counter.txt'; my $counter = 0; { local *FH; open(FH, "+<$file") || die $!; flock(FH, 2) || die $!; $counter = ; seek(FH, 0, 0); truncate(FH, 0); print FH $counter+1; close(FH); } print header(); print "counter[$counter]\n";