my @connection; foreach (@server_list) { my $ssh = Net::SSH::Perl->new($_) or next; push @connection, $ssh; } foreach my $ssh (@connection) { # ... }