Whoa, this match block has an O(n) loop nested inside another O(n) loop. Could these data structures be converted to hashes instead? Remember that Ruby as of 1.9 guarantees hash key order. If hash isn't appropriate, could we use a secondary index?