in reply to Using simultaneous threads

Here's a simple solution that can use if:
  1. your perl program doesn't need to process the output of mysqldump as it is being generated, and
  2. you don't need to wait for the mysqldump commands to finish
If both of these are true, then structure your code like this:
for my $db (keys %{$db_ds}) { ...figure out which table to dump, etc... system("$cmd > $dumpfile &"); }
The only difference will be that $cmd won't end with a pipe |. Moreover, since you are running mysqldump, you can also use the -r option to direct output to the dump file instead of redirecting standard output. Indeed, this is better since then you can use the safer, multi-argument version of system.

If you need to wait for the mysqldump commands to finish, then it is just a little bit trickier:

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);