in reply to transform array into a data structure

Data::Diver solves this problem nicely:

use strict; use warnings; use Data::Diver qw( DiveVal ); use Data::Dumper; my @pathparts = split(/\//, "dir1/dir2/dir3/file1"); my $href = {}; DiveVal( $href, @pathparts ) = 'value'; print Dumper( $href );
Note that I removed the leading slash on the path (for convenience). If you don't want empty strings as keys, you could strip them out using grep. This is left as an exercise for the reader.

Output:

$VAR1 = { 'dir1' => { 'dir2' => { 'dir3' => { 'file1' => 'value' } } } };