my @fh; for my $ip (@ips) { open my $fh,"|-","ssh $ip" or die "Can't ssh to $ip: $!\n"; push @fh, $fh; } while () { for my $fh (@fh) { print $fh $_; } }