my $remove = q{<div><div class="blue"></div></div>};

Don't use quoted string constructors to make regex patterns; use  qr// (update: to make honest-to-goodness regex objects) (see perlop, perlre, perlretut, and perlrequick). Using ordinary quoted string constructors sets you up for future puzzling bugs.

my $str = q{$line};

This is a meaningless statement; it just assigns a literal  $line to a string:

c:\@Work\Perl\monks>perl -wMstrict -le "my $str = q{$line}; print qq{'$str'}; " '$line'

my $str = qr{$line};

The problem here is that you seem to be trying to make the entire line you've just read from the file into a pattern. You then remove a piece of the pattern with a substitution:

c:\@Work\Perl\monks>perl -wMstrict -le "my $remove = qr{ now \s+ brown }xms; ;; my $line = qq{how now brown cow \n}; print qq{<$line>}; ;; my $str = qr{$line}; print $str; ;; ($line = $str) =~ s/$remove//; print qq{<$line>}; " <how now brown cow > (?^:how now brown cow ) <(?^:how cow )>
Do you see where the extraneous  (?^: ... ) stuff comes from?

Useless use of non-destructive substitution (s///r) in void context

You have to use a  s///r substitution in a statement like
    my $new_line_changed = $old_line_not_changed =~ s/$remove//gr;
(and I would recommend use of the  /g "global" modifier also).

Update: Changed variable names in last code example to (hopefully!) clarify the point being made.


Give a man a fish:  <%-{-{-{-<


In reply to Re^3: Strip specific html sequence by AnomalousMonk
in thread Strip specific html sequence by koober

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.