If you want to use a more list-like style (as in your example), you can work with this:
#!/usr/bin/env perl use strict; use warnings; use List::Util 'first'; use feature 'say'; my @filenames = qw(foo bar baz quux alice bob); my @forbidden = qw(f ba); my @matching = grep { my $filename = $_; not defined first { $filename =~ /^\Q$_/ } @forbidden; } @filenames; say for @matching;
Output:
quux alice bob
Note I used first here instead of core- grep because with long @forbidden lists it can be more efficient since it stops after the first (and maybe only) match.
source share