sub ParseIt { my $text = ''; open (MERLOG,$log) || die "Unable to open $log:$!\n"; while () { unless (/MAIL From.*?\n/smi) { # Continuation of record in progress $text .= $_; } else { # Found a new record examine_record($text); # $text = $_; } } # caveat for the last record because it will not be followed by a new record examine_record($text); }