Just use split. You are just looking 3 commas back in the list so:

while(<DATA>) { my ($name, $data) = split "="; my @data = split ',', $data; for my $i ( 0.. $#data ) { next unless $data[$i] eq 'ResGen'; # found a ResGen so see what we had 3 commas ago (do bounds chec +k to0) next if $i -3 < 0; my $back_a_bit = $data[$i -3]; print chop($back_a_bit) eq '"' ? "$name: Found quote\n" : "$name +: No quote\n"; } } __DATA__ GENE1="Rattus norvegicus serum and glucocorticoid-regulated kinase (sg +k) mRNA, complete cds,NM_019232,333,ResGen,ATP binding|protein serine +/threonine kinase|protein amino acid phosphorylation,,,,29517 GENE2="ESTs, Weakly similar to putative serine/threonine protein kinas +e MAK-V [M.musculus]",NM_144755,331,ResGen,,,,,246273 GENE3="Thiosulfate sulphurtransferase (rhodanese)",X56228,329,ResGen,m +itochondrion|sulfatetransport|thiosulfate sulfurtransferase,,,,25274 GENE4="Spleen tyrosine kinase,NM_012758,327,ResGen,ATP binding|protein + tyrosine kinase|intracellular signaling cascade|protein amino acid p +hosphorylation,,,,25155 GENE5="Spleen kinase 24,NM_012758,,ResGen,ATP binding|protein tyrosine + kinase|intracellular signaling cascade|protein amino acid phosphoryl +ation,,,,25155 __END__ GENE1: No quote GENE2: Found quote GENE3: Found quote GENE4: No quote GENE5: No quote

Update

Fixed typo thanks to Hoffmator

cheers

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print


In reply to Re: Need method to create Regular expression for known pattern in the middle of a line by tachyon
in thread Need method to create Regular expression for known pattern in the middle of a line by Ya

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.