#open the log #loop through $chunk_string = ""; while ($line = ) { #do any formatting (chomp etc) if ($line =~ /datestamp/) #appropriate regex here { if ($chunk_string =~ /whateveryouarelookingfor/) { #you found it in the current chunk } $current_datestamp = $1; #update the datestamp $line =~ s/$current_datestamp//; #ignore the date $chunk_string = ""; #reset the chunk. } $chunk_string .= $line; #add the line to the current chunk. }