Calls flock(2) on FILEHANDLE. See the flock (2) manpage for definition of OPERATION. Returns TRUE for success, FALSE on failure. Will produce a fatal error if used on a machine that doesn't implement flock(2). Here's a mailbox appender for BSD systems.
open(MBOX, >>/usr/spool/mail/$ENV{'USER'}") or die "Can't open mailbox: $!"; lock(); print MBOX $msg,"\n\n"; unlock();
Note that flock() can't lock things over the network. You need to do locking with fcntl() for that.