while(<DATA>){ print if /\s(12){3}$/; # match exactly 3 consecutive occurrences of 12 at the end of the line } __DATA__ Mary Betty Boop Mark 123 123 123 123