my %hash_of_arrays; $tmp =~ /(.+)(\d+)$/; $hash_of_arrays{$1}->[$2] = $the_thing_to_store ; use Data::Dumper; print Dumper(\%hash_of_arrays);