$server = "http://www.foo.com" $path = "/absolute/path/" $html = ' absolute with no dns http://absolute.with/dns.html relative/without/dns.html relative2 without dns.html '; $html =~ s/ (<\s* (?:a|img|area) [^>]+?(?:href|src) \s*=\s* ["']? ) ( [^'"\/>] [^'" >]+? ) ([ '"]?>) / $1.sprintf("%s%s", $path, $2).$3 /sigex; #### $html =~ s/ (<\s* (?:a|img|area) [^>]+?(?:href|src) \s*=\s* ["']? ) ( [^'"\/>(http|telnet|gopher|file|wais|ftp)] [^'" >]+? ) ([ '"]?>) / $1.sprintf("%s%s", $path, $2).$3 /sigex;