Use `inreplace`. See https://github.com/mxcl/homebrew/wiki/Formula-Cookbook#inreplace