my %hash; $hash{a}{key} = 7; $hash{b}{key} = 10; $hash{c}{key} = 11; $hash{d}{key} = 12; $hash{e}{key} = 13; foreach my $x (keys %hash) { printf "%02x\n", $hash{$x}{key}; } #### foreach my $id (sort keys %hash) { printf Out "%02x\n", $hash{$id}{"counter"}; }