my $text = "[id=###]blahblah[/id]; my $targetURL = "/cgi-bin/coolcode.pl?"; $text =~ s/.*[(id=.*)](.*)[\/id]/\2<\/a>/gs;