#!/usr/bin/perl ….. my @children = (); …… sub mysub { my $pid = fork(); if ($pid) { push(@children, $pid); } if( $pid == 0 ){ # child process code here exit 0; } } …… foreach (@children) { waitpid($_, 0); }