foreach $customer (@customers) { if ($cust_pid = fork) { #in parent sleep 1; $SIG{CHLD} = 'IGNORE'; } if ($cust_pid == 0) { #in child foreach $router (@routers) { if ($router_pid = fork) { #in parent sleep 1; $SIG{CHLD} = 'IGNORE'; } if ($router_pid == 0) { #in child #do something exit; #this exits child process at router level } } } exit; #this exits child process at customer level }