in reply to Array to nested hash

This is a fine opportunity to use List::Util's reduce function:
use List::Util qw( reduce ); sub array_to_nested_hash { reduce { scalar {$b,$a} } undef, reverse @_; }
Now, to test our subroutine:
use Data::Dumper; $Data::Dumper::Terse = 1; $Data::Dumper::Indent = 0; print Dumper( array_to_nested_hash(1..5) ), "\n"; # {'1' => {'2' => {'3' => {'4' => {'5' => undef}}}}}
Cheers,
Tom