in reply to Aligning Arrays Problem

Unfortunately I don't have the time to refractor your ruleset into code at the moment, however I may be able to answer some of your questions.

1. How can I create a scheme that can handle hashes with varying number of arrays (values)?

To determine the number of rows and columns contained in a given matrix, find the number of hash keys and the number of referenced array elements respectively.

scalar keys %hash; # rows scalar @{ $hash{'element'} }; # columns

2. I also have difficulty in implementing point 6 above. Don't know what's the construct to build.

This is by no means a definitive answer, but one possibility is to create a lookup "table" of the same dimensions. If a match is made, place a flag in the lookup, therefore reducing checking for prior matches to a mere lookup.