note
chipmunk
By "reverse grep", I take it that you mean you want to loop over a list of regexes with one string, rather than loop over a list of strings with one regex. As far as Perl is concerned, these are the same.
<p>
Your difficulty comes from thinking of Perl's [grep] as being the same as the command line grep. This is not the case. In Perl's grep, the conditional is not necessarily a pattern match; it is any arbitrary Perl expression. For example, you could do something like this:
<code>@results = grep { $_ & 1 } (1 .. 10)
</code>
to get a list of odd numbers between 1 and 10.
<p>
Thus, you can do any filtering you want with grep, with the proper conditional expression. What you're looking for could be written something like this (with some regexes I made up):
<code>my $url = 'http://www.perlmonks.org/';
my @regexes = ('/private(?:/|$)', 'python');
if (grep { $url =~ $_ } @regexes) {
# handle bad URL
} else {
# handle good URL
}
</code>
As suggested in another response, you'd probably want to precompile the regexes with qr// for efficiency.
148645
148645