while (my $host = pop @arrayofhosts) { # $host is no longer in the array defined (my $pid = fork) or die "Cannot fork: $!"; # self-explanatory unless ($pid) { # only the child will execute this code from here ... # do some things with $host exit 0; # very important!!! don't let it get past here # to here. At this point, the child process will terminate ... } # The parent continues here after forking the child # here it can do what it wants. # you can rest here a while so you don't have too many zombies sleep (10); # now do some more things before forking the next child process }