# Build the hash my %bad_ports = (12345=>1, 12346=>1, 20034=>1, 8787=>1, 31337=>1); # short list while () { my $port = extract_port_from($_); # fill in a regex here print if $bad_ports{$port}; }