Your question is still not completely clear to me. A good tool for this job is "regular expressions" or regex for short. If the regex succeeds, the left hand side assignment is defined otherwise it is not.

As an update note: If for some reason this doesn't do exactly what you want, I expect you to spend some time studying the code and for you to make a serious attempt at modifications. I think you are doomed if you just copy code without understanding how it works.

#!/usr/bin/perl use strict; use warnings; use List::Util qw(sum); while (<DATA>) { my ($var) = /:\>\>(\w+)/; # could have been done my (@nums) = /,\s*(\d+)/g; # on one line... next unless $var; # skips bogus lines print "$var,",sum(@nums),"\n"; } #prints: #test,10 #test1,26 __DATA__ <"Session Date:Mar 13/2017 ":>>test", 1,2,3,4 ":>>test1", 5,6,7,8 end>

In reply to Re^3: Skip lines until you find a delimiter >> by Marshall
in thread Skip lines until you find a delimiter >> by RohanGuddad

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.