Word permutations with restrictions