$ssh->register_handler("stderr", sub { my ($channel, $buffer) = @_; print " Unable to connect to $host\n" if ($buffer =~ /permission/i); });