in reply to Work-around for variable length look-behind?

If you use perl 5.10 or newer, you can use \K to exclude everything on its left from the subsitution:
1 while s/ \s [^b]* \K b (?=a) /B/x; # ^ only start the substitution here # ^ go to the first b # ^ only search second string

(Update: added the "before a" criterion)

Perl 6 - links to (nearly) everything that is Perl 6.