#!/usr/bin/perl use strict; use warnings; use Net::OpenSSH; my $host = "127.0.0.1"; # remote IP my $port = 22; # ssh default 22 change it my $passwd = "username"; my $user = "password"; my %opts = ( passwd => $passwd, port => $port, user => $user ); my $ssh = Net::OpenSSH->new( $host , %opts ); $ssh->error and die "Couldn't establish SSH connection: ". $ssh->error; my ($rout, $pid) = $ssh->pipe_out("vmstat") or die "pipe_out method failed: " . $ssh->error; open my $write, ">", "test.txt" or die $!; while (<$rout>) { print $write $_; } close $rout; close $write; open my $read, "<", "test.txt" or die $!; while (my $row = <$read>) { chomp $row; print "$row\n"; } close $read; __END__ Check also the test.txt file it contains the same output procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu----- r b swpd free buff cache si so bi bo in cs us sy id wa st 1 0 68716 390444 9520 674036 0 1 25 27 217 235 8 2 89 1 0