use strict; use warnings; my @nums; my @pids; my $max = 4; my $children = 0; foreach my $i ( 0 .. 10 ) { # for all IP's now just 0 to 10 pipe( READER, WRITE ); my $pid; if ( $children == $max ) { $pid = wait(); $children--; } if ( defined( $pid = fork() ) ) { if ($pid) { $children++; print "Parent: forked child ($pid)\n"; push @pids, $pid; close(WRITE); my $num = ; push @nums, ($num); close(READER); wait; } else { my $calc = 365 * $i; # just a example # on this place i will call the function, and capture the # return message print WRITE $calc; close(WRITE); exit; } } else { print "Error: failed to fork\n"; exit; } } for my $pid (@pids) { waitpid $pid, 0; } print "Numbers: @nums \n"; # on this place i will check the array of the return values