in reply to RE - match from right
though that seems a little excessive for this case. The other usual way to do it is:$string = reverse $string; $string =~ s/b/x/; $string = reverse $string;
or (at least as clunky as your original):$string =~ s/(.*)b/$1x/;
Finally, you can do it without using a regex at all:$string =~ m/.*(?=b)/g and $string =~ s/\Gb/x/;
substr($string, rindex($string, 'b'), 1) = 'x';
|
|---|