use strict; use warnings; my $found_match = 0; while () { s/\s+$//; if (/^\d/) { $found_match = 0; } if (!$found_match && /^\d*\s+(LA.*)/) { print("$1\n"); $found_match = 1; } } __DATA__ 1 LA-1-00 2 CON-1-0 LA-2-01 3 LA-03-2 LA-03-02