foreach my $item (LARGE_LIST) { $key = property($item); $record{$key} += 2; if(condition_is_true($item)) { $record{$key} |= 1; } } #### for my $key (keys %record) { my $count = $record{$key} >> 1; my $flag = $record{$key} & 1; print "$key\n" if $count >= 2 and $flag; # ... }