# I'd separate this out and put it in a configuration section of the script my $bad_ports = '12345|12346|20034|8787|31337|31338|54320|54321'; my $found = 0; while(){ print if (/\b($bad_ports)\b/o); }