A bit different....
#usr/bin.perl -w use strict; my $file1=<<END; test1.tst not_run test3.tst time:2 sec test6.tst time:2 sec test10009.tst timeL 39 sec END my $file2=<<END; test2.tst time:3 sec test3.tst time:6 sec test1.tst time:5 sec END open FILE1, '<', \$file1 or die "cannot open file1 $!"; open FILE2, '<', \$file2 or die "cannot open file2 $!"; my %seenFile1; while (<FILE1>) { my ($file_name) = $_ =~ (/^\s*(test\d\.tst)\s*/); $seenFile1{$file_name} = 1 if $file_name; } close FILE1; my @common; while (<FILE2>) { my ($file_name) = $_ =~ (/^\s*(test\d\.tst)\s*/); #as OP wants, save common names for other uses.... # push @common, $file_name if $seenFile1{$file_name}; } #one use is sort # foreach (sort {my ($Anum) = $a =~ /(\d+)/; my ($Bnum) = $b =~ /(\d+)/; $Anum <=> $Bnum }@common ) { print "$_\n"; } __END__ test1.tst test3.tst

In reply to Re: Extract common lines from 2 files by Marshall
in thread Extract common lines from 2 files by great_riyaz

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.