if (/^Article\b/) { s/\s*$//; # remove trailing whitespace and newlines print "Line [$_] is a heading."; };