..... my ($urltop) = 'http://www.somewhere.com/'; my ($urltodir) = 'http://www.somewhere.com/folder/'; my(@matches) = ($content =~ /href="([^"]*)"/gi); foreach my $match (@matches) { if ($match =~ /^http/i) { ## absolute leave alone } elsif ($match =~ /^\//) { $content =~ s/href="$match"/href="$urltop$match"/gi; } else { $content =~ s/href="$match"/href="$urltodir\/$match"/gi; } }