my $buffer = ""; while () { next unless /\S/; # Skip blank lines. if (/^\D/) { # A bar is a non-digit as well. chomp $buffer; $buffer .= $_; next; } print $buffer; $buffer = $_; } print $buffer;