Based on the limited info you've given so far, my suggestion would be to modify the performTask() sub. The first thing it needs to do is check if a lock file (i.e. semaphore/mutex file) is already created. If it is, either exit or wait depending on your needs. If it hasn't been created, then the sub will create it and continue doing its work. The last thing the sub should do is remove the lock file so that the next process can do its work.