amoss has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: Double for loops.
by FunkyMonk (Bishop) on Jul 19, 2007 at 18:09 UTC
    Depending on exactly what it is you want...

    for my $outer ( qr/hi/, qr/bye/ ) { print grep { /$outer/ } qw/ bike hello hi / }

    or

    my $outer = join "|", qw/ hi bye /; print grep { /$outer/ } qw/ bike hello hi /;

    or, if you want to know which pattern matched

    $outer = join "|", qw/ hi bye /; /($outer)/ and print $1 for qw/ bike hello-hi hi-ho /;
      I do need to know what pattern is matched, it that way more efficient than nesting two foreach loops?

        Efficiency means different things to different people in different circumstances. If you mean "is it faster", then Benchmark them.