use List::Util qw( shuffle ); my @pot; for (1..4) { (my $text_new = $text_orig) =~ s/[A-Z]{3,}/ @pot = shuffle @products if not @pot; pop(@pot) /eg; print($text_new); }