in reply to fork / threads script

May I suggest you take a look at Parallel::ForkManager-I have used it a number of times so I would not have to worry about keeping track of the number of processes that are running (just set a number, and when one finishes, it handles spawning off the next one. (Bonus: One of the examples in the documentation is a file downloader.)

Hope that helps.