my $ports = '(?:'.join('|', @win_ports).')'; while () { print if ( m#$regex/$ports#o ); }