my $cmd = '/opt/rssh/bin/ssh'; my $machine = "remote_machine"; open(my $fh, "-|", "$cmd $machine \"hostname;sleep 5;uptime\" 2>&1") or die "cannot open fh"; my $flags = fcntl($fh, F_GETFL, 0) or die "\ncan't get flags for the pipe: $!\n"; fcntl($fh, F_SETFL, $flags | O_NONBLOCK) or die "\ncan't set flags: $!\n"; my $out = $fh; my $bytes_read = -1; my $blocksize = 1024; my $result = ""; my $buf; $bytes_read = sysread($out, $buf, $blocksize); print "\nl buf content is:\n $buf \n"; close $out;