in reply to flock till ya get it right

Why reopen the file if your object is to get a lock? Try something like:
open(FILE, ">file.dat") or die "file.dat: $!"; while ( ! flock(FILE, 2) ) { # you *might* want to consider bailing out at # some point. } truncate FILE, 0; # important! to avoid corrupted files print FILE, "blah\n"; close(FILE); }
The truncate call is there to avoid the nasty race condition that happens when someone else manages to also open the file for writing and then writes into it prior to your getting the lock.