in reply to replacing chunks of text only if another chunk matches a pattern

$_ = <<'HTML'; <a href="http://www.foobar.com/xxx"> <a href="http://www.danheller.com/xxx"> <a href="http://www.foobar.com/xxx"> <a href="http://www.danheller.com/xxx"> HTML s{(href="http://(?!www\.danheller\.com)[^"]+")}{$1 target="_blank"}g; print;

Results:

<a href="http://www.foobar.com/xxx" target="_blank"> <a href="http://www.danheller.com/xxx"> <a href="http://www.foobar.com/xxx" target="_blank"> <a href="http://www.danheller.com/xxx">