In general, with Perl, do not mess with $1 or $2, etc variables. There are exceptions, this is not one of them.

#!/usr/bin/perl use warnings; use strict; my @data; while (<DATA>) { next if ( /^\s*$/ ); #skip blank lines # easy way to to get numbers after "=" my ($tag1, $tag2, $extra) = /\s*=\s*(\d+)/g; #skip malformed lines.. #must be 2 number tokens after "=" if (defined $tag1 and defined $tag2 and not defined $extra) { print "$tag1 \t$tag2\n"; } else { print "Bad Line:$_"; } } =prints 12345 99999 Bad Line:blabla;tag1=12345;blabla Bad Line:awdrfaf; tag2 = 122345; 6768 9876 Bad Line:079a8; tag1 =345; tag2 = 895; tag3=3987; 12567 98999 7899 8977 =cut __DATA__ blabla;tag1=12345;blabla;tag2=99999 blabla;tag1=12345;blabla awdrfaf; tag2 = 122345; asdf;tag 1 = 6768; tag2= 9876; 079a8; tag1 =345; tag2 = 895; tag3=3987; blabla;tag1 =12567;blabla;tag2= 98999 blabla;tag1= 7899;blabla; tag2 =8977

In reply to Re: ambiguous regex match by Marshall
in thread ambiguous regex match by Hosen1989

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.