#!/usr/bin/perl use strict; use warnings; use Net::SSH2; my $ssh2 = Net::SSH2->new(); $ssh2->connect('hostname', 22) or $ssh2->die_with_error; my $chan = $ssh2->channel() or $ssh2->die_with_error; $chan->blocking(0); $chan->exec("ls ./") or $ssh2->die_with_error; while (<$chan>){ print } print "exit status: " . $chan->exit_status . "\n"; $ssh2->disconnect();