#pseudo code use Parallel::ForkManager; my @names = (); my %list = (); my %thing = (); $threads = 20 my $pfm = new Parallel::ForkManager( $threads ); $pfm->run_on_finish( sub { my ($pid, $exit_code, $ident, $exit_signal, $core_dump, $data_stru +cture_reference) = @_; my $name = $data_structure_reference->{name}; %list = $data_structure_reference->{data1}; $thing{$name}{a} = $data_structure_reference->{thing1}; $thing{$name}{b} = $data_structure_reference->{thing2}; push @names, $data_structure_reference->{name}; }); }); FOREACH: foreach my $thing(keys %{$things_hr}) { my $pid = $pfm->start and next; #do stuff push @names, $name; #do stuff $thing1{$name}{a} = $value1; $thing{$name}{b} = $value2; #do stuff Foreach $id:{ $list{$id}{$name}{b} = $b; $list{$id}{$name}{e} = $b1; $list{$id}{$name}{a} = 0; $list{$id}{$name}{c} = $ar->[$id][3]; $list{$id}{$name}{i} = $ar->[$id][1]; $list{$id}{$name}{j} = $ar->[$id][2]; $list{$id}{$name}{k} = sprintf("%.4f",$ar->[$id][9]); } $pfm->finish( 0, { data1 => %id, name => $sample_name, thing1 => $value1, thing2 => $value2,}); $pfm->wait_all_children;