Code snippet $chan->exec("$command\n"); # Could I use only this channel to run all the commands $chan->ext_data(merge); my $readbuffer2; # buffer for reading 500 bytes of data my $buflen=256; my $numbytesread = 0; $fullcmdoutput2 = $fullcmdoutput2."\n***********$testdfsioclean**************\n"; while (!$chan->eof) { $numbytesread = $chan->read($readbuffer2, $buflen); if ($numbytesread > 0) { $TDOutput->Print($readbuffer2); $fullcmdoutput2 = $fullcmdoutput2.$readbuffer2; #concatenate data from buffer with aggregate command output } } $fullcmdoutput = $fullcmdoutput."\n**********************************\n"; my $cmd_exit_status = 255; $cmd_exit_status = $chan->exit_status; if ($cmd_exit_status == 0) { ........... } else { ........... }