in reply to Get total number of characters in a hash (not memory usage)

{ 'key' => 'value' } # should be 7

Should be 8, shouldn't it? Anyway, you can take advantage of the fact that a hash in list context evaluates to the key/value pairs.

my $hashref = { 'key' => 'value' }; my $sum1 = 0; $sum1 += length for %$hashref; # - or - my $sum2 = length join '', %$hashref; # - or - use List::Util qw/sum/; my $sum3 = sum map {length} %$hashref;

I suspect the first of these will be most efficient since it doesn't build an intermediate string or list - Update: at least, I think it doesn't; I hope for %hash is optimized to use an iterator, but I'm not certain at the moment. If you wanted to play it super safe:

my $sum4 = 0; while ( my ($k, $v) = each %$hashref ) { $sum4 += length($k) + length($v) }