# Hash, this is what you have my %hoh = ( ... ); # walk each key/value pair contained in the hash reference stored in $hoh{$sid} while ( my ( $key, $value ) = each %{ $hoh{$sid} } ) { ... } # Hash reference, what generated the error my $hoh = { ... }; # walk each key/value pair contained in the hash reference stored in $hoh->{$sid} while ( my ( $key, $value ) = each %{ $hoh->{$sid} } ) { ... }