use File::Temp 'tempfile'; my ($fh, $output) = tempfile(); close($fh); open my $remote, "| ssh $user\@$hostname >$tempfile" or die "Couldn't launch ssh ssh $user\@$hostname: $!"; print $remote "some test command\n"; print $remote "another test command\n"; print $remote "quit\n"; open my $fh, '<', $tempfile or die "Couldn't read the tempfile?!"; while(<$fh>) { print "Remote: $_"; };