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 );