use Parallel::ForkManager; # Max number or processes you want to fork at one time. # Set this to something reasonable so you don't thrash your box. my $MAX_PROCESSES = 5; # J. Random list of numbers. my @things = (1..10); my $pm = new Parallel::ForkManager($MAX_PROCESSES); # Start looping through my list of numbers foreach my $thing (@things) { # This is more of a loud comment than anything else, # just telling you that the parent is about to # fork a child. print "Forking off $thing...\n"; # Kick off the child process. # If this is the parent process, # we'll move on to the next step in this loop $pm->start and next; # This is your child process. # There are many like it, but this one is yours. :) # Do your forked goodness here print "$thing\n"; $pm->finish; # The child has finished. Tell him to clean up his room. } $pm->wait_all_children;