in reply to regex in form !regex->regex<-!regex

Gentle forestcreature: I strongly endorse the wise advice of others to use a proper HTML parser, but here's another (very) naive regex approach using the Special Backtracking Control Verbs of 5.10+ (see perlre):

>perl -wMstrict -le "my $s = qq{foo\nbar\t<pRe> no\nnot\tnever </PrE> x\ty\nz }; ;; my %replace = ( qq{\n} => '<br/>', qq{\t} => '&nbsp; &nbsp; &nbsp;', ); ;; my $pre = qr{ (?i) <pre> [^<]* </pre> }xms; ;; print qq{[[$s]]}; $s =~ s{ $pre (*SKIP) (*FAIL) | ([\n\t]) }{$replace{$1}}xmsg; print qq{[[$s]]}; " [[foo bar <pRe> no not never </PrE> x y z ]] [[foo<br/>bar&nbsp; &nbsp; &nbsp;<pRe> no not never </PrE> x&nbsp; &nbsp; &nbsp;y<br/>z ]]