in reply to perl Expect

Did you look at Net::SSH::Expect? I have not used it personally, but it does have methods for collecting the input into strings. I assume by 'output' you really mean input. You obviously know what you are outputting :)