---->0702995-42.2017.8.01.0002 being the number i want to use to batch clean the document, keeping only the first time it found, completely wiping out the rest. [underlined emphases added]

I'm also confused by your OPed statement of requirements. I will concentrate on the above quoted section therefrom, so maybe something like:

c:\@Work\Perl\monks>perl -wMstrict -le "use Data::Dump qw(dd); ;; my @lines = ( 'line 1 this line has no Foo number: keep', 'line 2 Foo something 1234-12.3 other 123 first valid keep', 'TOSS 3 Foo toss this 1234-12.3 line 123 DELETE', 'line 4 Foo not same 1234-12.3 offset 123 line keep', 'line 5 Foox not tag 1234-12.3 same offset 123 keep', 'line 6 has no Foo number: keep', 'line 7 Foo yyyy xxx 1234-12.3 this line keep', 'line 8 Foo xxxx zzzz 1234-12.4 different n keep', 'TOSS 9 Foo kill this 1234-12.3 one DELETE', 'line 10 no Foo number: keep', ); dd \@lines; print qq{\n}; ;; my $strange_n = qr{ (?<! \d) \d+ - \d+ (?: [.] \d+)* (?! \d) }xms; my $toss_tag = qr{ \b Foo \b }xms; ;; my $rx_can_toss = qr{ \A .+ $toss_tag \D* ($strange_n) }xms; ;; my ($valid_was_seen, $sn, $sn_offset); ;; my @keep_lines; LINE: for my $i (0 .. $#lines) { my ($sn_seen, $this_sn, $this_sn_offset) = map { $_ ? (1, $1, $-[1]) : () } $lines[$i] =~ $rx_can_toss ; if ($sn_seen) { if ($valid_was_seen) { next LINE if $sn eq $this_sn and $sn_offset eq $this_sn_offset; } else { ($valid_was_seen, $sn, $sn_offset) = (1, $this_sn, $this_sn_off +set); } } push @keep_lines, $lines[$i]; } dd \@keep_lines; " [ "line 1 this line has no Foo number: keep", "line 2 Foo something 1234-12.3 other 123 first valid keep", "TOSS 3 Foo toss this 1234-12.3 line 123 DELETE", "line 4 Foo not same 1234-12.3 offset 123 line keep", "line 5 Foox not tag 1234-12.3 same offset 123 keep", "line 6 has no Foo number: keep", "line 7 Foo yyyy xxx 1234-12.3 this line keep", "line 8 Foo xxxx zzzz 1234-12.4 different n keep", "TOSS 9 Foo kill this 1234-12.3 one DELETE", "line 10 no Foo number: keep", ] [ "line 1 this line has no Foo number: keep", "line 2 Foo something 1234-12.3 other 123 first valid keep", "line 4 Foo not same 1234-12.3 offset 123 line keep", "line 5 Foox not tag 1234-12.3 same offset 123 keep", "line 6 has no Foo number: keep", "line 7 Foo yyyy xxx 1234-12.3 this line keep", "line 8 Foo xxxx zzzz 1234-12.4 different n keep", "line 10 no Foo number: keep", ]
(And in addition to an SSCCE, in future please also consider How to ask better questions using Test::More and sample data.)


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


In reply to Re: Array Exact Position Filter by AnomalousMonk
in thread Array Exact Position Filter by Perolizador

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.