If you lock a file for writing, it will automatically wait untill any other lock is released. In other words you can do this in both processes and it'll work:
use Fcntl qw(:flock); # import LOCK_* constants
open F,">>",$somefile or die $!;
flock(F,LOCK_EX); # lock exclusively - waits for lock
# write stuff here
close(F); # close() will release the lock.
|