my %new; foreach my $key (keys %old} { if(....) { $new{$key} = $old{$key}; # do further processing. } else { print STDERR "dropped key: $key\n"; } }