$ perl -MO=Deparse -e 's/s/http://example.com/[404 Not Found]/g' Bareword found where operator expected at -e line 1, near "404 Not" (Missing operator before Not?) syntax error at -e line 1, near "404 Not Found" -e had compilation errors. #### $ perl -MO=Deparse -e 's/http://example.com/[404 Not Found]/g' Bareword found where operator expected at -e line 1, near "404 Not" (Missing operator before Not?) Regexp modifiers "/a" and "/l" are mutually exclusive at -e line 1, at end of line syntax error at -e line 1, near "404 Not Found" -e had compilation errors. #### $ perl -MO=Deparse -e 's{http://example.com}{[404 Not Found]}g' s[http://example.com][[404 Not Found]]g; -e syntax OK #### #!/usr/bin/env perl -l use strict; use warnings; use Inline::Files; my %bad_url; while () { chomp; ++$bad_url{$_}; } my $re = qr{(?x: ( # capture entire element to \$1 # match end of 'a' start tag \s* # match optional whitespace \g2 # match href value (captured in \$2) \s* # match optional whitespace # match 'a' end tag ) # end \$1 capture )}; my $replace = '[404 Not Found]'; for my $fh (\*HTM1, \*HTM2) { my $html = do { local $/; <$fh> }; print '*** ORIGINAL ***'; print $html; $html =~ s/$re/exists $bad_url{$2} ? $replace : $1/eg; print '*** MODIFIED ***'; print $html; } __URLLIST__ http://bad1.com/ http://bad2.com/ http://bad3.com/ http://bad4.com/ __HTM1__

HTM1

http://bad1.com/ http://good.com/ http://bad2.com/ __HTM2__

HTM2

http://good.com/ http://bad2.com/ http://good.com/ http://bad3.com/ http://bad3.com/ http://bad4.com/ ##
## *** ORIGINAL ***

HTM1

http://bad1.com/ http://good.com/ http://bad2.com/ *** MODIFIED ***

HTM1

[404 Not Found] http://good.com/ [404 Not Found] *** ORIGINAL ***

HTM2

http://good.com/ http://bad2.com/ http://good.com/ http://bad3.com/ http://bad3.com/ http://bad4.com/ *** MODIFIED ***

HTM2

http://good.com/ [404 Not Found] http://good.com/ [404 Not Found] http://bad3.com/ [404 Not Found]