while ($fh) { /^Confname/ or next; work_with $_; last; ## if you want to process only the first ocurrence of such line }