- Do you really want to lock the whole directory, or just ensure one copy of a.pl is running at a time?
- Will the files always be created/overwritten on execution of a.pl, or can they be appended to?
- Will there be other programs/scripts/etc that create/write/append to these log files?
You could either use
flock or use sysopen with O_CREAT|O_EXCL on a file a.pl.lck in that directory. Handling error conditions is left as an exercise to the writer.