use warnings; use strict; my ($to_be_printed); while () { chomp; if (/\d\d-\w{3}-\d\d/) { print $to_be_printed, "\n" if $to_be_printed; $to_be_printed = $_; next; } $to_be_printed .= " $_"; } print $to_be_printed, "\n"; __DATA__ 23-Dec-07 12:34 A B C D E F G H I JJ KK L 23-Dec-07 12:35 A B C D E F GG HH II J K L M N O P Q 24-Dec-08 15:15 AA B C D E F GG