use Algorithm::Combinatorics qw[ variations_with_repetition ];; $i = variations_with_repetition( [ 'a'..'z' ], 3 );; $" = ''; print "@$_" while $_ = $i->next;; aaa aab aac aad ...