in reply to N Permutations of M Items

It sounds as though what you want is pretty close to this. Maybe you can use it as a basis for your code. You might also try Algorithm::ChooseSubsets.

HTH, --traveler