use strict; use warnings; use Data::Dumper; my @columns = qw/ title1 title2 title3 title4 field1 field2 field3 field4 /; my $struct_ref = [ @columns[4..7] ]; # place the 'fields' into an array ref. $#columns = 3; # truncate the original CSV row array, @columns. foreach my $col ( reverse @columns ) { $struct_ref = { $col => $struct_ref }; } print Dumper $struct_ref;