$num_keys = scalar keys %hash; #### $number = grep(//, keys %hash); for (keys %hash) { $number++; } #### ## Find the number of elements that are defined: $number = grep(defined $hash{$_}, keys %hash); ## Find the number of elements that are "true": $number = grep($_, values %hash); ## Find the number of elements where the key equals the value: $number = grep($_ eq $hash{$_}, keys %hash);