in reply to Sort of a permutation

Might the CPAN modules List::Permutor or Algorithm::Permute be useful? (The latter even uses the interface of the former!)