When I had the question of "which filehandle to flock", because I was reading a file, then writing the file, requiring me to close, then reopen it (in retrospect, I probably should have just used seek or some such), the solution was to flock a wholly separate file instead, eg.
open LCK, "$file.lck";
flock(LCK, LOCK_EX);
# operate on how ever many files here
flock(LCK, LOCK_UN);
close LCK;
Of course, this only protects you from other instances of the same program, or other programs that use the same mechanism.
--Bob Niederman, http://bob-n.com
All code given here is UNTESTED unless otherwise stated.