Hi james28909,

Let me try re-frame what you are trying to do and work within that premises as your intent in this post is not clear to me. More so, probably showing the content of both searchfile and key file, and the format of how your final output will look like would have also help.

That said, I think you want to read dataset from your searchfile into three scalar variables, then use those to search lines from another file called key file to search and get the corresponding values of the three variables. If that is right, one of the ways you can achieve your aim is like so:

use warnings; use strict; use Inline::Files; use Data::Dumper; my %set = map { chomp; $_ => undef } <SEARCHFILE>; while (<DATA>) { if ( my ( $key, $value ) = /^(.+)=(.+)\s+</ ) { if ( exists $set{$key} ) { push @{ $set{$key} }, $value; } } } print Dumper \%set; __SEARCHFILE__ revision version type __DATA__ revision=0.0.1.1 <--newline at end of line version=0.0.1 <--newline at end of line type=A <--newline at end of line key1=64 characters <--newline at end of line key2=32 character <--search will stop before going to newline revision=0.0.2.1 <--newline at end of line version=0.0.2 <--newline at end of line type=B <--newline at end of line key1=64 characters <--newline at end of line key2=32 character <--search will stop before going to newline revision=0.0.3.1 <--newline at end of line version=0.0.3 <--newline at end of line type=C <--newline at end of line key1=64 characters <--newline at end of line key2=32 character <--search will stop before going to newline revision=0.0.4.1 <--newline at end of line

OUTPUT:
$VAR1 = { 'revision' => [ '0.0.1.1', '0.0.2.1', '0.0.3.1', '0.0.4.1' ], 'version' => [ '0.0.1', '0.0.2', '0.0.3' ], 'type' => [ 'A', 'B', 'C' ] };
Note: This might not meet your need but should get you a look into what you are doing. The regex I used might also not work for you even if my premises is correct ( hope so ) You might also want to see How do I post a question effectively?.
All I did, was to get data from searchfile as keys of an hash, then using a regex, pick out what I need from the key file, if the hash keys exists. Then display it.
If you tell me, I'll forget.
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author unknown to me

In reply to Re: searching for multiple matches and then seek from last match by 2teez
in thread searching for multiple matches and then seek from last match by james28909

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.