Here's a subroutine that solves the problem if you want
an *exact* match - no regex supported. The solution can
be extended to regexes, but you have to be careful,
iterating with m//g over a line to "find all matches"
will fail, as m//g will never find overlapping matches.
sub multi_match {
my ($large, $small) = @_;
my @large = split /\n/ => $large;
my @small = split /\n/ => $small;
my $first = $small [0];
foreach my $i (0 .. @large - @small) {
my $pos = 0;
LOOP:
while ((my $new_pos = index ($large [$i], $first, $pos)) != -1
+) {
$pos = $new_pos + 1;
foreach my $j (1 .. $#small) {
next LOOP unless
length $large [$j] >= $new_pos + length $small [$
+j] &&
$small [$j] eq substr $large [$i + $j], $new_pos,
length $small [$j];
}
return ($i, $new_pos);
}
}
return;
}