#!/usr/bin/perl -w use strict; use LWP::Simple qw(get); use HTML::Parser; use URI::Escape; my $new_link = "http://www.baz.com/cgi-bin/doubleclick.cgi?url="; my $url = $ARGV[0] or die "usage: $0 http://www.foo.com/bar.html\n"; my $file = get($url) or die "Cannot get the page '$url'\n"; my $parser = HTML::Parser->new( default_h => [ sub { print shift }, 'text' ], start_h => [ \&modify_link, 'tagname, attr, text' ], )->parse($file); sub modify_link { my ( $tagname, $attr, $text ) = @_; print $text and return if $tagname ne 'a'; $attr->{href} = $new_link . uri_escape( $attr->{href} ); print ''; } __END__