my @bad = qw(fork smurf); my $regex = join('|', @bad); $regex = qr/$regex/; foreach (){ if(/^[0000-9999](.+)/){ next if /$regex/; push( @witty_quotes, substr( $_, 5) ); } else { next }; } #### 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); } }