in reply to Does Semaphore Work?
in thread Safe Counter

This looks an awful lot like two previously discussed threads. Please see Safe Counter and Safe Counter Follow Up for more information. Reusing an existing working module is likely your best option. See the File::CounterFile module (which is mentioned in the other threads.)