for my $host (...) { $ssh{$host} = Net::OpenSSH->new($host, ...); if($ssh{$host}->error) { print STDOUT "Still waiting for SSH. Retrying in 5 seconds...\n"; sleep 5; redo; } else { print STDOUT "SSHD is back up. Continuing...\n"; } }