in reply to converting a hash based matrix into an array based matrix

Why was the matrix put in as a hash in the first place? If you have a large, sparse matrix, then moving to an array could be quite expensive.

One of my sayings is that the best way to clean up a mess is to not make one in the first place. For data structures, the best way to convert is to build the final structure from the beginning if possible.

If those keys are fixed as the print on line 29 suggests, you could make a hash that maps ' '=>0, A=>1, C=>2, etc. Then use it somewhat like:$matrix->[$indexfor{$key}][$indexfor{$key2}] ++;