#!/usr/bin/perl use strict; use warnings; use diagnostics; use Net::SSH::Perl; my $host = 'localhost'; my $host1 = 'localhost'; my $host2 = 'localhost'; my $pass = 'password'; my $user = 'user'; my $domain = 'localhost.localdomain'; my @hosts = qw(host1, host2); my $lscmd = 'ls -ltr'; foreach $host (@hosts) { print "$host\n"; my $ssh = Net::SSH::Perl->new($host1, protocol => '1,2', debug => 1); $ssh->login($user, $pass); my ($stdout, $stderr, $exit) = $ssh->cmd($lscmd); print $stdout, "\n"; }