sub main_script() { my @servers ('a', 'b'); my %con_opts; $con_opts{timeout} = 120; $con_opts{async} = 1; my $script = "some_script.pl"; my %opts; $opts{stdin_pipe} = 1; $opts{stdout_pipe} = 1; $opts{stderr_to_stdout} = 1; foreach @servers { $con_opts{host} = $_; $ssh{'SSH'} = Net::OpenSSH->new(%con_opts); ($ssh{'STDIN'}, $ssh{'STDOUT'}, undef, $ssh{'PID'}) = $ssh{'SSH'}->open_ex(\%opts, $script) or die "Error ".$ssh{$host}->error; } ## Waitpid loop to clean up terminating OpenSSH sessions }