Your Hash stored format: $VAR1 = { 'A' => { 'B' => {} } }; #### This output is now stored..so, using this you can get the key output A B C..so, assign some value for the key if you stored values in hash $VAR1 = { 'A' => { 'B' => { 'C' => 1 } } }; #### #!/usr/bin/perl use Data::Dumper; my %line; $why = ""; $a = A; $b = B; $c = C; $line{$a}{$b}{$c} = 1; print Dumper(\%line); $i = 1; for $a (keys %line) { for $b (keys %{$line{$a}}) { for $c (keys %{$line{$a}{$b}}) { print "$a $b $c\n"; } } }

It prints output : A B C