It smells to me like you're on Windows, and that you need to use
binmode on both in- and output of that proxy, so that it becomes more transparent — meaning it will no longer change anything. That way you'll get the wretched "\cM" characters everywhere, even in your headers, so you will might have to change the code a little, to accomodate for them.