PCHR = ["K", "Q", "R", "B", "N", "P"] w1 = "QRKPNB" w2 = "".join(sorted(w1, key=PCHR.index)) # Translate this to Perl ... print(w1 + " -> " + w2)