in reply to Losing or overwritting values

Not commenting on the rest of the problem, but since I saw this code in some of the replies as well..
open(USEDPW, "> $usedpw") or die "crap on me for writing $!"; flock USEDPW, 2;
This code is always wrong. You have already zeroed the file before you've gotten permission to zero the file.

You need to open the file for reading and writing without altering it, get the flock, then proceed. Many correct examples exist. This is not one of them.

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.