use Fcntl qw(:DEFAULT :flock); use IO::File; # [...] my $mbox = new IO::File $cMailBoxFile, O_RDWR or logthis("could not open <$cMailBoxFile> for read/write: $!"; flock $mbox, LOCK_EX; logthis("opened and locked <$cMailBoxFile>");