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