in reply to Re: Returning from a subroutine.
in thread Returning from a subroutine.

35 #Q: How many times is the $search found inside all the hash values? +? ... 41 #Q: How many hash values contain at least one "$search" inside of t +hem? ...
These two loops do the same thing. ...

But 'how many times is X found in all hash values?' and 'how many values contain at least one X?' are two different questions. A hash might have many values, but only one or two of those values might have an X. However, the total number of Xs in those few values might be very many.

>perl -wMstrict -le "my %hash = ( x => '---------', y => '-----x---', z => '-XxX-x-X-', ); my $Xs_in_values = 0; $Xs_in_values += () = /X/gi for values %hash; print $Xs_in_values; my $values_with_X = grep /X/i, values %hash; print $values_with_X; " 6 2

Update: The code of the OP for answering these two questions seems correct, although a bit klunky.