#!/usr/bin/perl use strict; use warnings; use Data::Dumper; use Net::OpenSSH; # $Net::OpenSSH::debug = -1; my $host = 'localhost'; my %opts = ( user => "user", port => "22", # default # psw => "psw", key_path => "/home/user/.ssh/id_rsa" ); my $ssh = Net::OpenSSH->new($host, %opts); $ssh->error and die "Can't ssh to $host: " . $ssh->error; my @ls = $ssh->capture("ls"); $ssh->error and die "remote ls command failed: " . $ssh->error; chomp (@ls); print Dumper \@ls; __END__ $ perl test.pl $VAR1 = [ 'Desktop', 'Documents', . . . ];