This should work for you:
use strict; my %bad = ("Zwire6" => 1, "zwire7" => 1);#this is case sensitive open(OUT, ">", "out.txt"); my @section; my $adjust = 0; my $is_server = 0; my $server_id; my $throw_away = 0; my $line; while ($line = <DATA>) { chomp($line); if ($line =~ m/^\[/) { flush_section(); $#section = -1; $throw_away = 0; push @section, $line; if ($line =~ m/^\[server(\d+)\]/) { $server_id = $1; $is_server = 1; } else { $is_server = 0; } } else { push @section, $line; if ($is_server) { if ($line =~ m/^servername\s*=\s*(.*?)\s*$/) { if (defined($bad{$1})) { $throw_away = 1; $adjust ++; } } } } } flush_section(); close(OUT); sub flush_section { if (!$throw_away) { if ($is_server) { $section[0] = "[server".($server_id - $adjust)."]"; } foreach my $line (@section) { print OUT $line, "\n"; } } } __DATA__ [reports] yearlystore = quarterlystore = monthlystore = weeklystore = dailystore = [server1] logfilepath1 = F:\Logfiles\ZWire\Zwire4\split-0\ex*.log servername = Zwire4 logfilepassword = logfileusername = id = a104136320003954 [server2] servername = Zwire6 logfilepath1 = f:\logfiles\zwire\zwire6\split-0\ex*.log id = a104136346513171 logfilepassword = logfileusername = [server3] logfilepath1 = F:\Logfiles\ZWire\Zwire4\split-0\ex*.log servername = Zwire4 logfilepassword = logfileusername = id = a104136320003954 [server4] id = a104136351461256 logfilepath1 = f:\logfiles\zwire\zwire7\split-0\ex*.log logfilepassword = servername = zwire7

In reply to Re: Searching for and removing multi-line file entries by pg
in thread Searching for and removing multi-line file entries by ibanix

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.