my %ssh; my @hosts = qw/ server1.example.com server2.example.com /; my @cmd = "list of shell commands ending with reboot"; for my $host (@hosts) { $ssh{$host} = Net::OpenSSH->new($host, master_opts => [-i => "/path/to/ssh_key"], async => 1); $ssh{$host}->error and die "SSH connection to $host failed: " . $ssh{$host}->error; } for my $host (@hosts) { $ssh{$host}->system("@cmd"); }