use Proc::Queue size => 8; for my $dir (@dirs) { run_back { chdir $dir and exec "foo_matrix"; }; } 1 while wait > 0;