for (@port_file) { $match = 1 if (/^Port\s*$port/); undef $match if (/^#-+/); print if ($match); }