my @logentries = (); my $toss = 1; my $monthRegex = join("|",qw/Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec/); while () { if(/^($monthRegex)\s+d{1,2}\s+(\d{2}:){3}/) { push(@logentries,$_); $toss = 0; # unless you want to ignore some of'em # in which case: $toss++; } else { $logentries[$#logentries] .= $_ unless $toss; } } foreach (@logentries) { # decide what to do with each entry, # handling XML content with a suitable module when necessary } #### my $entry = ""; while () { if(/^($monthRegex)\s+d{1,2}\s+(\d{2}:){3}/) { $result = &handleEntry( $entry ) if $entry; $entry = $_; # unless you want to ignore some of'em # in which case: $entry = ""; } else { $entry .= $_ if $entry; } } $result = &handleEntry( $entry ) if $entry; # and replace the "foreach" loop in the previous version # with "sub handleEntry { ... }"