my $ssh = Net::SSH::Expect->new ( host => "$current_server", user => "$user", raw_pty => 1 ); # test the login eval { $login_output = $ssh->run_ssh(); }; # I've tried to capture $@ or $! here but it never gives me anything useful my $rc = eval{($ssh->read_all(2) =~ />\s*|$\s*\z/) or die "where's the remote prompt?";}; unless($rc =~ /$your_expected_output_match_pattern/){ &MOVE_ON_TO_THE_NEXT_HOST; } $ssh->exec("stty raw -echo");