Fix issue with execution of perl due to gsub not matching across newlines
Land #4356