If you want to iterate on all the permutations of n elements, you could use Algorithm::Permute (which, IIRC, should contain even the code from Algorithm::FastPermute), with something like this (taken from docs):
my @array = (1..9);
Algorithm::Permute::permute { print "@array\n" } @array;