in reply to Connecting to STDIN and STDOUT over SSH

If you don't need it to work on Windows, use Net::OpenSSH:
my $ssh = Net::OpenSSH->new($SERVER, user => $USER, master_opts => [-i => $KEYFILE], master_stderr_discard => 1); $ssh->error and die "unable to connect to remote host: " . $ssh->error +; my $out = $ssh->capture({stdin_data => $lines});