> ... could be used to generate groups of multiple QRY... lines

One way to do it is the (?{ collect() })(*FAIL) trick

use v5.12; # https://perlmonks.org/?node_ +id=11146744 use warnings; use Data::Dump qw/pp dd/; #pp my ($paths,$cmds) = data(); my $re = join "|", map {"\Q$_\E" } @$paths; for my $cmd (@$cmds) { my @matches; $cmd =~ m{ ^CMD=" ($re) #/? # final / is missing (?!\.) # no empty name before .extens +ion ([^/]+) "$ (?{push @matches,[$1,$2]}) (*FAIL) }x; pp {$cmd => \@matches}; } sub data { return [ qw( /a /a/b /a/b/c /b /b/c /c /ab /abc /abcd )] , [ qw( CMD="/a/a.sh" CMD="/aa.sh" CMD="/ab.sh" CMD="/abc.sh" CMD="/a/bc.sh" CMD="/a/b/c.sh" CMD="/a/b/c/.sh" CMD="/a/b/cd.sh" CMD="/a/b/c/d.sh" CMD="/x/y.z" CMD="/a/xyz.sh" CMD="/abcd.sh" ), q(CMD="/a/very 'special' command.exe") ] }

But while my results are in sync with

>

QRY(4)="/a/bc.sh" QRY(4)="/ab/c.sh"

they differ significantly because my understanding is that the OP said that all CMDs have a missing final slash. I also disallowed files starting with a dot like .sh

{ "CMD=\"/a/a.sh\"" => [] } { "CMD=\"/aa.sh\"" => [["/a", "a.sh"]] } { "CMD=\"/ab.sh\"" => [["/a", "b.sh"]] } { "CMD=\"/abc.sh\"" => [["/a", "bc.sh"], ["/ab", "c.sh"]] } { "CMD=\"/a/bc.sh\"" => [["/a/b", "c.sh"]] } { "CMD=\"/a/b/c.sh\"" => [] } { "CMD=\"/a/b/c/.sh\"" => [] } { "CMD=\"/a/b/cd.sh\"" => [["/a/b/c", "d.sh"]] } { "CMD=\"/a/b/c/d.sh\"" => [] } { "CMD=\"/x/y.z\"" => [] } { "CMD=\"/a/xyz.sh\"" => [] } { "CMD=\"/abcd.sh\"" => [["/a", "bcd.sh"], ["/ab", "cd.sh"], ["/abc", +"d.sh"]], } { "CMD=\"/a/very 'special' command.exe\"" => [] }

YMMV, but other interpretations of the OP are easily implemented by (un)commenting the two documented lines in the regex.

update
Output using
/? # final / is missing #(?!\.) # no empty name before .exten +sion

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery


In reply to Re^4: In place replacement from reference list by LanX
in thread In place replacement from reference list by Misstre

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.