... $test_hash{$group} = $group; for (my $i = 0; $i < scalar @vals; $i++){ $test_hash{$group}{$vals[$i]} = $vals[$i]; } ...