$ perl -MData::Dumper -MData::Diver=DiveVal -E 'DiveVal($x = {}, qw(1 2 3)); say Dumper $x' $VAR1 = { '1' => [ undef, undef, [ undef, undef, undef, undef ] ] }; #### #!/usr/bin/perl use warnings; use strict; use File::Find; use Data::Dumper; use Data::Diver qw (DiveVal); my @extracted = ; push @extracted, 'end'; my @currentpath = (); my $structure = {}; for my $i (0 .. $#extracted) { my @list = split /;/, $extracted[$i]; my @list2 = split /;/, $extracted[$i+1]; if ($list2[0] eq 'end') { last } if ($list2[0] gt $list[0]) { push @currentpath, $list[1]; } else { my @req = (@currentpath, $list[1], 'required'); DiveVal($structure, @req) = $list[3]; pop @currentpath if $list2[0] lt $list[0]; } } print Dumper($structure);