my $ssh = Net::OpenSSH->new(...); my ($in, $out, $pid) = $ssh->open2(); # passing no cmd will start a shell print {$in} "ls\n"; while (<$out>) { print "out: $_"; last if /$prompt_re/; } print {$in} "pwd\n"; ...