my @array1 = (1..5); # N my @array2 = qw/a b/; for my $val1 (@array1) { # Start N processes here that can run in parallel # Each process outputs data to its own separate file # I will need it in the future for my $val2 (@array2) { # For each of the N processes, wait until it is done, # then start 2 parallel processes which use # the output data as input # Save the output of each process separately to 2N files # (two files with N elements would be better, but as I # couldn't figure that out, I just postprocess the data ;-) } } # "waitallchildren" or equivalent # Postprocess step to reduce the final output to 2 files