in reply to process handling

use Net::SSH::Perl; ($out, $err, $exit) = $ssh->cmd($cmd, [ $stdin ])

If I understand you correctly this should work for you. See This

...the majority is always wrong, and always the last to know about it...