in reply to Perl script works differently from Apache then CMD line

There are several ways to run Perl scripts from Apache, but at least under mod_perl STDIN and STDOUT are not regular file handles (backed by a operating system file descriptor) and that can interfere with Net::OpenSSH.

Specifically the remote SSH server may not like having its stdin stream closed. Try redirecting it from a pipe:

pipe my($r_pipe), my($w_pipe); $ssh->capture({stdin_fh => $r_pipe}, ...);