print join'',map{ chr 97+rand(6) } 1 .. 2 for 1 .. 100; ## Slightly wasteful, but you only do it once ## and reuse the array each time. my @pairs = grep{ /[a-f]{2}/ }'aa' .. 'ff'; print $pairs[ rand @pairs ];