use strict; use warnings; my $label1 = 'L1'; my $label2 = 'L2'; my %hash; @hash{'a' .. 'h'} = ( {$label1 => 1 }, {$label1 => 2 }, {$label2 => 3 }, {$label1 => 4 }, {$label2 => 5 }, {$label1 => 6 }, {$label2 => 7 }, {$label1 => 8 }, ); while ( my( $key,$subhash ) = each %hash) { print "$key: $subhash->{$label1}\n" if exists $subhash->{$label1}; }