my $super_regex = join '|', sort {length $b <=> length $a} map quotemeta($_), @list; $var_val =~ s/($super_regex)/$prefix$1$suffix/g;