use strict; use warnings; my @ips = (1 .. 10); my %pipe; for my $ip (@ips) { pipe my $reader, my $writer; my $pid = fork; die "Error: failed to fork\n" if not defined $pid; if ($pid) { close $writer; $pipe{$ip} = $reader; } else { sleep $ip; print $writer 365*$ip; exit; } } my @nums; for my $ip (@ips) { my $handle = $pipe{$ip}; # Necessary to avoid glob mapping push @nums, <$handle>; } 1 while (wait != -1); print "Numbers: @nums \n"; #### if ( $children == $max ) { wait(); }