# define the anon arrays here instead of in the child foreach(@doms) { $mxs{$_} = []; } for( 1..$PREFORK ) { last unless @doms > 0; my $url = shift @doms; child( $url ) if !fork(); } wait(); # wait till one dies; my $kid; { if( @doms > 0 ) { my $url = shift @doms; child( $url ) if !fork(); } $kid = wait(); redo unless $kid == -1; } print Data::Dumper->Dump([\%mxs]); exit;