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

I think the following works, at least for the limited input set. It relies on the RE engine matching the leftmost pattern first, and on your input data having a unique delimiter (the whitespace), so it doesn't fall back to the "verbatim" section of the RE:

perl -wlpe "s/(^\w+ )|\G(b)(?=a)|\G(.)|/$1 || uc $2 || $3/ge"

Update: I forgot about the "followed by 'a'" condition. Should work now, again.