Perl mutiple children creation
I think this can be improved by using queues as the main construct to convey what is going on.

First, you have a pending queue:

my @pending = (8, 8, 5);


Second, you have an empty queue with the currently active workers:

my @workers;


And this queue has a size limit:

my $max_workers = 2;


This can all be run by a single while loop:

while(@workers &lt; $max_workers) {
    ... add one more worker ...
    ... remove all workers that are done ...
    ... break out of loop is @pending and @workers are both empty
    ... wait for a worker to exit (or sleep) ...
}


When this loop exits, you're all done.