for my $db (keys %{$db_ds}) { ...figure out which table to dump, etc... unless (defined(my $pid = fork)) { die "unable to fork: $!\n"; } if ($pid == 0) { exec("$cmd > $dumpfile"); die "unable to exec for table $table: $!\n"; } } # now wait for all the children to finish 1 while (wait > 0);