$input = "I am the letter LETTERAAAAAAAAAA like AAAlpha AAAAnd I will always be the first in LETTERAAAAAlphabet.";
$output = preg_replace('/(?:\G|(LETTER))A/', '$1B', $input);
echo $output;
Expected output:
I am the letter LETTERBBBBBBBBBB like AAAlpha AAAAnd I will always be the first in LETTERBBBBAlphabet.
Explanation: