Disclaimer: I have yet to have had to do any real work with locking; what I know comes from a lot of theory I've read on the subject. Ok, now that we've dealt with that,
I would think the following is perfectly valid, and perfect period:
use Fcntl qw(:DEFAULT :flock :seek);
sysopen FH, "file.name", O_RDWR | O_CREAT or die "horribly - $!"; # no
+ O_TRUNC!!
flock FH, LOCK_EX or die "screaming - $!";
my @slurp = <FH>;
do_something_with(\@slurp);
seek FH, 0, SEEK_SET;
print FH @slurp;
truncate FH, tell FH;
close FH;
As far as I can tell, it deals with everything. It requires no semaphore files so I needn't worry about potential write permission woes nor cleaning up after myself when I exit, and it operates on exactly one filehandle, which is the one holding the lock. Someone tell me if there's something missing in my picture; if not, then I believe (barring other requirements) this is The Way To Do It.
Makeshifts last the longest.