in reply to Howto Dynamically Create a Hash?

First of all, the answer you got manually was wrong. 'F' contains 25, not 16, all the 16's went to 'B' already.

use strict; use Data::Dumper; my @nlist = (3,24,8,17,23,14,17,9,16,24,25,11,22,14,14,8,19,16,15,8); my @key_list = ('A'..'Z'); my $hoa; my $key_index = -1; while (@nlist) { $hoa->{$key_list[++$key_index]}[0] = splice(@nlist, 0, 1); my $i = 0; while ($i <= $#nlist) { if ($nlist[$i] % $hoa->{$key_list[$key_index]}[0]) { $i ++; } else { push @{$hoa->{$key_list[$key_index]}}, splice(@nlist, $i, +1); } } } print Dumper $hoa ;