#!/usr/bin/perl use forks; use forks::shared; use strict; use warnings; my $num = "10"; my @results = (); share(@results); my @children = (); for my $i (0..$num-1) { my $pid = fork(); if ($pid) { # Parent push @children, $pid; } elsif ($pid == 0) { # Child my $result = "abc"; # Later to be replaced with the # actual thing to be computed $results[$i] = $result; sleep 3; exit(0); } } foreach (@children) { waitpid($_, 0); } for (my $r=0 ; $r<@results; $r++) { print $r . "\t" . $results[$r] . "\n"; }