my $line=''; while () { # build line chomp; if (/^(.*)\\$/) { $line .= $1; #or maybe $line .= "$1 "; ??? next; } $line .= $_; # ... do line processing here ... if ($line =~ /^Data_Value/) { ... } elsif ($line =~ /^Data_Group/) { ... } elsif ($line =~ /^Data_Raw/) { ... } # reset state $line = ''; }