Use unpack to split your string into pairs, and then unpack again, this time discarding the first character (otherwise you would get only pairs where the first index is even).
Then use either your counting technique, or a hash.
And benchmark it!
Update: This posting is irrelevant since I interpreted the original question wrongly.
In reply to Re: Speeding permutation counting
by moritz
in thread Speeding permutation counting
by albert
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |