my @hashNames = qw(testA testB testC); my $i = 0; my %hoh; foreach (@hashNames) { $hoh{$_}->{key} = $i; } # later print $hoh{testA}->{key};