use strict; my @names = qw(name age location); # add do this list whenever # make a hash reference and populate it my $fields = {}; # declare $fields being a hash reference @$fields{@names} = ( ... list of corresponding values ...);