use strict; my $find = qr/^(?:H0|HT)/; open (NEW, ">", "OUTPUT.txt" ) or die "could not open:$!"; open (FILE, "<", "INPUT.txt") or die "could not open:$!"; while () { print NEW if (/^\s{32}\S\s$find/); } close (FILE); close (NEW);