in reply to Re^3: counting instances of one array in another array
in thread counting instances of one array in another array

And then you're back to the OPs problem again: the array @perm. Which will be huge.