my @pathparts = split(/\//, "/dir1/dir2/dir3/file1"); my %hash; #### $hash{"dir1"}{"dir2"}{"dir3"}{"file1"}