use Fcntl; #contains codes to use for flock ... open(STORE,">$storable_file") || die "Could not open $storable_file: $!\n"; flock STORE,LOCK_EX; store_fd \%hash,\*STORE; ... # code code code flock STORE,LOCK_UN; close(STORE); # closing file also unlocks it, but I prefer explicit unlocking