s~(?:^[^a]*(?:a[^a]*){2}a~$1b~;