The man pages for ssh gives:
ssh exits with the exit status of the remote command or with 255 if an error occurred.
The doc for
Net::SSH::Perl says:
($out, $err, $exit) = $ssh->cmd($cmd, [ $stdin ])Runs the command $cmd on the remote server and returns the stdout, stderr, and exit status of that command.
For telnet, my man pages do not document a return code (!), whereas
Net::Telnet has a large section devoted to errmode, which you might like to read.