in reply to using a regex which is in a string

Something like this:

my $c = 'aaabbbaaa'; my $d = 's/b/c/g'; eval "\$c =~ $d"; die "Failure: $@\n" if $@; print $c, "\n";

Depending on where your $d is coming from, this could expose you to code injection. Be cautious.

Also notice I refrained from using $a and $b. This is usually a good idea, as the use of $a and $b can get confusing since sort uses special global versions of $a and $b also.


Dave