use strict; use warnings; local $/ = "\n##"; #record separator while () { chomp; #print "\n<<<$_>>>\n"; # check input my ($head,$rest) = /^ (.*?) \n (.*) $/xs; # print record only if $rest contains alphanumerics print "##$_" if $rest =~ /\w/; } __DATA__ ## This gets stripped ## This doesn't Because it contains this line ## More headers blah blah ## This should not get stripped, but it does ### This should prevent it from getting stripped, but it doesn't stuff #### This should also not get stripped ##### But it does