Does anyone know a more efficient way to loop through the hash within another loop of the same hash? Is there a more efficient way to calculate all permutations?