Not positive I've understood your question correctly, but are you looking for something like this?
#!/usr/bin/perl use 5.016; use warnings; # 1069225 save match templates for reuse? my $regex = qr/(sdfsd|abc|def|hijk)/; say "\t regex is: $regex\n"; my @string = ('xyzalmnopdef', 'sdfsd', 'hijk lmn op', 'babcdefijk2345', 'xaybz3', ); for my $string(@string) { if ( $string =~ /($regex)/g ) { # /g only if you expect to # find more than one match per li +ne say "got a match in $string: $1"; }else{ say "\t No match found in $string"; } }
Execution:
C:\>1069225.pl regex is: (?^u:(sdfsd|abc|def|hijk)) got a match in xyzalmnopdef: def got a match in sdfsd: sdfsd got a match in hijk lmn op: hijk got a match in babcdefijk2345: abc No match found in xaybz3 C:\>

At the worst, perhaps this offers some help.

Update/PS: Failed to explain the /g. Fixed with comment in code.

If I've misconstrued your question or the logic needed to answer it, I offer my apologies to all those electrons which were inconvenienced by the creation of this post.

In reply to Re: Storing pattern matches by ww
in thread Storing pattern matches by joshywashy

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.