in reply to look-behind regex

following not-lookbehind regex:
s/^(.*?)foo/my $x=$1; $x.($x=~m[toto]?"foo":"bar")/e
does the work, but does it meets your requirements?

Courage, the Cowardly Dog