you can combine this into a single gsub that takes a block, this also means you can remove the check in the if statement and simply always execute the gsub. This means instead of running 1 to 3 regexpes per line we always run just one.