my $prev; while () { if (/^\s*$/ && $prev =~ /^\s*$/) { # Two blank lines in a row found } $prev = $_; }