$ perl use warnings; use strict; my @codes = (" length $a } @codes; my $text = "testing a link: boofle"; print "in: $text\n"; $text =~ s/($codes_regex)/lc $1/gie; print "out: $text\n"; __END__ output with the sort: in: testing a link: boofle out: testing a link: boofle and without: in: testing a link: boofle out: testing a link: boofle