use Fcntl qw/:flock/; ... open flock($fh, FLOCK_EX); # or: flock($fh, FLOCK_SH); ...