my @fail_servers; for my $server (@servers) { # do your thing with $server push @failed_servers, $server unless change_password($server); }