instead of taking the whole string after a <br> and replacing it with itself, do gsub(/^<br>/, ""). don't need the bang either.