if ( flock( LOCK, 2 || 4 ) )
Down with magic numbers! This code is unnecessarily platform dependent. Use the
Fcntl module to get the appropriate constants (as shown in the documentation for
flock). (BTW, I'm assuming that the logical instead of bitwise or is just a typo.)
use Fcntl ':flock';
# ...
if ( flock( LOCK, LOCK_EX | LOCK_NB ) )
# ...
P.S. Regarding sleeping...
How can I sleep() or alarm() for under a second?