#!/usr/bin/perl -w use strict; my %hash = ( 'I' => 1, 'II' => { 'A' => 3, 'B' => { '1' => 4, '2' => 5, '3' => 6} }, 'III' => 2 ); print_hash(\%hash); sub print_hash { my($href) = @_; foreach my $key (keys %$href) { if (ref($$href{$key}) eq 'HASH') { my $href2 = $$href{$key}; print_hash($href2); } else { print "$key => $$href{$key}\n"; } } }