Thank you Bill for answer. It works, but was not able to remove the empty comments along with that.

#######Remove power using remove_power_list ########### my $outfile; my $arr_content; my $rprow = join '|', @remove_power_list; $rprow = qr/(?:$rprow)/; if (@remove_power_list != 0) { my $bf_content; open $bf_content, '<', $bf_bind; ###bf_bind is file in bigger +for loop my @bf_array = <$bf_content>; close $bf_content; open $outfile, '>', $bf_bind; for $arr_content (@bf_array){ next if (@arr_content=~/$rprow/); print $outfile $arr_content; } close $outfile; }

I think if there is any other string (not in my intended lines) matching with the element (for example "vcchg") from @remove_power_list array, should it remove those lines too. I tested some cases by putting string like: "set intfcInstName vcchg", outside or inside my unintended block and it doesn't delete, which is good. But, I don't know why.


In reply to Re^2: Remove multiple lines in file if pattern found based on array element, in perl by MatD
in thread Remove multiple lines in file if pattern found based on array element, in perl by MatD

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.