for my $host (@hosts) { for ( [ cmd1 => \@cmd1 ], [ cmd2 => \@cmd2 ], ) { my ($action, $cmd) = @$_; $pm->start("$action on $host") and next; exec(@$cmd, $host); print(STDERR "$action exec failed: $!\n"); _exit($!); } }