use strict; # use this array to simulate 10 tasks my @array = qw(zero one two three four five six seven eight nine ten); my $count=0; my $num_of_tasks = 5; for (1..$num_of_tasks) { my $pid = fork(); if ($pid) { $count++; waitpid($pid,0); } elsif ($pid == 0) { test(); } else { die "couldn’t fork: $!\n"; } } print "Done\n\n"; sub test { # do the work here print "text=$array[$count]\n"; sleep 1; exit(0); }