Using perl instead of sed which doesn't seem to work with newlines on MacOSX