my ($out, $pid) = $ssh->pipe_out("$cmd"); my $sel = new IO::Select($out); my $str = ""; while (1) { @ready = $sel->can_read(1); if(@ready > 0) { if(my $new = <$out>) { $str .= $new; } else { last; } } if ($ConnectionDeadline < time()) { kill 15, $pid; $str .= "\nConnection timeout\n"; last; } }