in reply to matching the non-presence of a string

arturo is right, the problem is too complex to be handled just using regexp's (what about the base element?)

Nonetheless I'll give it a go, as it demonstrate one of my favourite techniques... I just grab the href attribute in the first regexp and then use a subroutine to analyze it and modify it appropriately. I think this should work for simple links:

#!/bin/perl -w use strict; my $server = "http://www.foo.com"; my $path = "/absolute/path/"; while( <DATA>) { s{<\s*a\s*href=(['"])(.*?)\1\s*>([^<]*)</a>} { build_link( $2, $3) }seg; # hand ou +t the updating to a subroutine print; } sub build_link # here we + can play with the href attribute { my( $href, $text)= @_; if( $href=~ m{^(http|telnet|gopher|file|wais|ftp)://}) { return qq{<a href="$href">$text</a>}; } elsif( $href=~ m{^/}) { return qq{<a href="$server$href">$text</a>}; } else { return qq{<a href="$server$path$href">$text</a>}; } } __DATA__ <a href="/absolute/no/dns">absolute with no dns</a> <a href="http://absolute.with/dns.html">http://absolute.with/dns.html< +/a> <a href="relative/without/dns.html">relative/without/dns.html</a> <a href="relative2/without/dns.html">relative2 without dns.html</a> <a href="relative/without/dns.html">relative/without/dns.html</a> <a name="toto">toto</a>