while (@command) { my @pid; for $cmd (splice @command, 0, $how_many_parallel) { say $cmd; push @pid, system(1, $cmd); } for $pid (@pid) { $pid == waitpid $pid or die; $? and die; } }