in reply to error stating flock requires more args

Try:
lock(*FH); sub lock { my $fh = shift; flock($fh,LOCK_EX); }
The reason is, that FH is not known to lock, cause it's only visible inside your add() sub.
----------------------------------- --the good, the bad and the physi-- -----------------------------------