use strict; my @witty_quotes; my @bad = qw(fork smurf); my $regex = join('|', @bad); $regex = qr/$regex/; # open() FH somewhere foreach (){ # Note: it's important to put this regex test # outside of the if() block to ensure that $1 # below comes from the correct pattern match next if /$regex/; if(/^\d{4}(.+)/){ push( @witty_quotes, $1); } }