You don't need a pattern for that, split will do:

use Data::Dumper; my %found; while (<DATA>) { my ($file, @vers) = split " "; if (-f $file) { $found{$file} = [ @vers ]; } } print Dumper(\%found); __DATA__ Files Checked IN: test/abc.txt 1.23 1.3.4.5 team/hello.cpp 2.1 NONE Clear/thing.pl NONE 1.2.34 etc etc

Output:

$VAR1 = { 'Clear/thing.pl' => [ 'NONE', '1.2.34' ], 'team/hello.cpp' => [ '2.1', 'NONE' ], 'test/abc.txt' => [ '1.23', '1.3.4.5' ] };

You write

Need to call this pattern in one line..(requirement of my script)

Do you mind to tell why you do have such a requirement?

<update>

Anyways, you want the /g modifier on your pattern, and thus you can't say

if ( $var =~ m{$pattern}g ) {

because that will match only once (but without resetting the match location). If you really have to match globally and evaluate the result in a scalar (or boolean) context, you have to write something like

if ( (@matches = $var =~ m{$pattern}g ) > 0) {

which is ugly and not very readable. Anyways, here it is...

$var="Files Checked IN: test/abc.txt 1.23 1.3.4.5 team/hello.cpp 2.1 NONE Clear/thing.pl NONE 1.2.34 etc etc"; my $pattern = '([\w./]+)\s+([\d.]+|NONE)\s+([\d.]+|NONE)'; if ( ( @matches = $var =~ m{$pattern}g ) >0 ) { print join('|',@matches),$/; }

</update>


In reply to Re^3: Repeated Pattern Matching Fails by shmem
in thread Repeated Pattern Matching Fails by kapila

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.