use Fcntl qw( flock ); sub write_hits { open HITSW, "+< $_[0]" or die $!; flock HITSW, LOCK_EX; my $read_hits = ; chomp $read_hits; ++$read_hits; seek HITSW,0,0 or die $!; print HITSW $read_hits, $/ or die $!; close HITSW or die $!; return $read_hits; }