my @bad_ports = qw(12345 12346 20034 8787 31337 31338 54320 54321); while(){ foreach my $port (@bad_ports) { if (/\b$port\b/) { print; last; } } }