my $index=0; foreach my $thread (@threads) #wait for all threads until the end and insert results to hash { $hash_results{$index}=$thread->join; $index++; } return %hash_results;