use strict; use warnings; while ( my $file = glob '*.txt' ) { open my $fh, '<', $file; my $headers = grep /^>/, <$fh>; if ($headers <= 3) { unlink $file; } }