#!/usr/bin/perl use strict; use warnings; use Net::OpenSSH; my @hosts = ("host.name.1.edu", "host.name.2.edu"); my %conn = map { $_ => Net::OpenSSH->new(host => $_, user => 'user', port => 22, password => 'password'); } @hosts; open (my $fh, ">filename.txt"); # print $fh "testing\n"; foreach(@hosts) { $conn{$_}->spawn({stdout_fh => $fh},'hostname'); } open(FILE1, ") { chomp $line1; print "$line1\n"; }