Yet another approach... replace $test with whatever string you are looking for :) Good luck :)
use strict; my (@BUFFER,@FINAL); my $num; my $test = "Zwire6"; my $reorder = 0; my $remove = 0; while(<DATA>){ if(/$test/ig){ $remove = 1; } # set flag to remove if found if(/\[server(\d+)\]/){ if($remove == 1){ undef @BUFFER; $remove = 0; $reorder = 1;} if($reorder == 1) { $_ =~s/server$1/server$num/;} # renumber the servers push @FINAL, @BUFFER; # transfer BUFFER to FINAL undef @BUFFER; # empty BUFFER push @BUFFER, $_; # start over :) $num = scalar $1; next; } push @BUFFER, $_; } if($remove == 1){ undef @BUFFER; $remove = 0; $reorder=1; } push @FINAL, @BUFFER; #transfer the last print @FINAL; # or send it to yer handle :) __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] 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 JamesNC
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.