use List::Util qw( none ); my $text = 'f000124_9019_90181234_dp'; my $sites = [ '018', '324' ]; if ($text =~ /_9(...)/, none {$1 eq $_} @$sites) { print "$1 doesn't match anything: to be removed..\n" } #### 019 doesn't match anything: to be removed..