sub getsshrsa { my $thisFunc = ( caller(0) )[3]; my $opts = shift; my $ip = $opts->{ip}; $opts->{timeout} = 5 if (!$opts->{timeout}); my $ssh = Net::SSH::Expect->new ( host => $ip, user => $opts->{user}, password => $opts->{password}, ssh_option => "-T", raw_pty => 1 ); my $error = undef; $ssh->run_ssh() or $error = "SSH process couldn't start: $!"; return $error if ($error); $ssh->send(" "); sleep 2; my $output = $ssh->read_all(5); # <-- fails here return $ssh; }