in reply to Posting form data from within a virtual browser

One thing that looks missing is passing along the POST parameters to the URL you're fetching, unless the post sub does that.

I see that you're trying to rewrite all links to add a surfurl parameter to the URL. If the request is a POST instead of GET request, you may have to use a different CGI function (url_param) to get to the parameters from the URL.

An approach you might consider is to use a Web proxy that rewrites the headers, then configuring your browser to use the proxy. Proxies are designed for this sort of thing, and IIRC there are lots of modules that do the bulk of the work.