OK. From what I've understood you to want... see if something along these lines works any better:

use strict ; use warnings ; my $data ; { local $/ ; $data = <DATA> ; } ; my $s = 'bc' ; # Substring to search for in left hand side my @r = ($data =~ m/$s[^\s]*[ \t]+(.*)/g) ; print "@r\n" ; __DATA__ abcd s1 efgh s2 ijklm s3 nopq s4 bc s5 aqbc s6 rst s7 uvwx s8 yz s9
noting that the [ \t]+ can be changed to simply \t for use with your file (I've used [ \t]+ here only because that works even if the stuff between the "blocks" has been converted to any mixture tabs and spaces). Noting also that the (.*) will stop at end of line.

Note also that this is assuming that the right hand side will not contain any tabs (or spaces)

The regex can match to the search substring in the right hand side, but since that ends in a newline, the [^\s]*[ \t]+ part will fail the match.

The following:

my $data = "\n" ; { local $/ ; $data .= <DATA> ; } ; my $s = 'bc' ; # Substring to search for in left hand side my @r = ($data =~ m/\n.*?$s[^\s]*[ \t]+(.*)/g) ;
avoids matching in the right hand side, and the right hand side can contain tabs (and spaces). I don't have enough data to know if there's any performance advantage or disadvantage here.


In reply to Re^3: performance issues by gone2015
in thread performance issues by perlcat

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.