in reply to Flock Updating Counter

Or may take a look at How to apply flock.

Important : The filelock is gone, when you close the filehandle.