use strict; use DateTime::Format::Flexible; use DateTime::Duration; my $one_hour = DateTime::Duration->new(hours => 1); my %loglines; while () { next unless /TWO/; # only handle log-items with for channel TWO my ($time, $ref) = /(.*) UTC.*refs = (\d+)$/; my $dt = DateTime::Format::Flexible->build( $time ); if (defined $loglines{$ref}) { my $difference = $dt->subtract_datetime( $loglines{$ref}->[0] ); if (DateTime::Duration->compare( $difference, $one_hour) == 1 ) { # check if difference more than 1 hour print $loglines{$ref}->[1], $_, "-------------------------\n"; delete $loglines{$ref}; # reset the item } } else { $loglines{$ref} = [$dt, $_]; # save the item } } __DATA__ 2008-Jan-06 00:00:01 UTC (GMT +0000) - Poll: channel = ONE, refs = 595166299 2007-Jan-06 00:00:01 UTC (GMT +0000) - Poll: channel = TWO, refs = 595159906 2007-Jan-06 00:00:01 UTC (GMT +0000) - Poll: channel = THREE, refs = 659975924 2007-Jan-06 00:00:04 UTC (GMT +0000) - Poll: channel = ONE, refs = 595148941 2007-Jan-06 00:00:04 UTC (GMT +0000) - Poll: channel = TWO, refs = 595131400 2007-Jan-06 00:00:04 UTC (GMT +0000) - Poll: channel = THREE, refs = 659975924 2007-Jan-06 00:00:04 UTC (GMT +0000) - Poll: channel = ONE, refs = 595159906 2007-Jan-06 01:00:05 UTC (GMT +0000) - Poll: channel = ONE, refs = 595166299 2007-Jan-06 01:00:06 UTC (GMT +0000) - Poll: channel = TWO, refs = 595131400 2007-Jan-06 01:00:06 UTC (GMT +0000) - Poll: channel = TWO, refs = 659975924 2007-Jan-06 01:00:07 UTC (GMT +0000) - Poll: channel = THREE, refs = 595148941 #### 2007-Jan-06 00:00:04 UTC (GMT +0000) - Poll: channel = TWO, refs = 595131400 2007-Jan-06 01:00:06 UTC (GMT +0000) - Poll: channel = TWO, refs = 595131400 -------------------------