use strict; use warnings; while ( my $file = glob '*.txt' ) { print "Debug: found file $file\n"; open my $fh, '<', $file or die "Cannot open file $file: $!"; my $headers = grep /^>/, <$fh>; if ($headers <= 3) { unlink $file or die "Cannot unlink file $file: $!"; } else { print "Debug: file $file only has $headers headers - skipping\n"; } }