sub make_hash { my $keys= shift; return 1 unless $keys and @$keys; my $key= shift @$keys; return { $key => make_hash( $keys ) }; } my $hash= make_hash( [qw(one two three)] ); use Data::Dumper; print Dumper $hash; __END__ $VAR1 = { 'one' => { 'two' => { 'three' => 1 } } };