in reply to perl substitute
(update: deleted some phrases about random coding)
To answer your question, your substitutes only operate on $_ not $doc.
Cheers Rolf
( addicted to the Perl Programming Language)