elsif ( $ssh->error ) { # handle connection error my $lasterr = File::ReadBackwards->new("ssh_$host.log")->readline; # ... something that outputs or logs the error message }