sub other_walk { my ($indent, $item) = @_; print ' ' x (2 * $indent); print $item, "\n"; for (@{$hash{$item}}){ other_walk($indent+1, $_); } } other_walk(0, 1);