$foo = reverse $foo;
$foo =~ s/b/X/;
$foo = reverse $foo;
there's probably a more succinct way to write this.
Update:
i haven't tested this (or the other one actually), but something like this might work... find a 'b' that isn't followed by any more 'b's:
s/b[^b]*$/X/;
Update:
After reading
Transient's post (below), i realized my second regex is wrong. should be
s/b([^b]*)$/X$1/, but now i feel like i just ripped it off from him.