Usually, the easiest (and very often fastest) way to check whether two pieces of data are permutation of each other (of whether strings are palindromes), is to sort the individual data items of both data inputs and to check whether they compare equal.

It probably is not possible to recognize the fastest way to do anything. It of course is possible to compare alternate approaches. This is what benchmark does. Below, I propose two solutions to your problem and compare them. (Laurent outlined the first while I was preparing this post.)

Code

use strict; use warnings; use Test::Simple tests => 2; use List::MoreUtils qw(all);

The results show that both approaches work correctly (at least for this test case). The sort approach is more than twice as fast as the hash approach. Results will be different with real data. Good Luck, Bill