state-o-dis-array,
You may well be able to reduce the n^2 loops down to 2n at the expense of some memory. I won't pretend to know the relationship between the keys you are looking for but it looks like the number following the X is a multiple of 12, and the number following the : is an integer counter. It might be as simple as the following pseudo code:
- Loop over the array as for ( 0 .. $#array ) {...}
- push the index into a hash as push @{ $lookup{ $array[$_] } }, $_;
- Loop back over the array as for ( @array ) {...}
- Transform each element into the possibilities you are looking for
- Lookup the possibilities in the hash to see if the key exists