#!/usr/bin/perl -w use strict; use CGI; use LWP::Simple; my $query = new CGI; my $basename = 'http://www.perlmonks.org/'; my $script = 'http://www.someserver.com/path/to/script.cgi'; # I track the actual URL as a hidden field in the HTML my $url = defined $query->param('url') ? $query->param('url') : $basename; # Default to $basename if no $url exists my $content = get (defined $url ? $url : $basename); # Add a hidden field with actual URL after tag $content =~ s!(]*>)!$1!; # Have absolute paths go through this script $content =~ s!href="$basename!href="$script?url=$basename!gi; # Have relative paths go through this script $content =~ s!href\s*=\s*"/!href="$script?url=$basename!gi; # In the following regex, note the following: # Code tags are translated as #
...
# # and are optional. This is turned off if we use "Large font code" # Quotes around -1 in the font tag are optional. They don't always exist. # I discovered that in examining source for "Death to Dot Star!" my $code_regex = '
(?:)?([^<]+)(?:)?
'; # These will be used to create the download link my $href1 = '

Download this code

'; my $i = 0; while ($content =~ m!($code_regex)!go) { my $match = $1; $content =~ s!$match!$match$href1$i$href2!; $i++; } print $query->header; print $content;