for my $key (keys %record) { my $count = $record{$key} >> 1; my $flag = $record{$key} & 1; print "$key\n" if $count >= 2 and $flag; # ... }