in reply to comb a logfile for time diff and occourance

Somewhat shorter than other suggestions (by using the Date::Time modules):
use strict; use DateTime::Format::Flexible; use DateTime::Duration; my $one_hour = DateTime::Duration->new(hours => 1); my %loglines; while (<DATA>) { 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 = 595 +166299 2007-Jan-06 00:00:01 UTC (GMT +0000) - Poll: channel = TWO, refs = 595 +159906 2007-Jan-06 00:00:01 UTC (GMT +0000) - Poll: channel = THREE, refs = 6 +59975924 2007-Jan-06 00:00:04 UTC (GMT +0000) - Poll: channel = ONE, refs = 595 +148941 2007-Jan-06 00:00:04 UTC (GMT +0000) - Poll: channel = TWO, refs = 595 +131400 2007-Jan-06 00:00:04 UTC (GMT +0000) - Poll: channel = THREE, refs = 6 +59975924 2007-Jan-06 00:00:04 UTC (GMT +0000) - Poll: channel = ONE, refs = 595 +159906 2007-Jan-06 01:00:05 UTC (GMT +0000) - Poll: channel = ONE, refs = 595 +166299 2007-Jan-06 01:00:06 UTC (GMT +0000) - Poll: channel = TWO, refs = 595 +131400 2007-Jan-06 01:00:06 UTC (GMT +0000) - Poll: channel = TWO, refs = 659 +975924 2007-Jan-06 01:00:07 UTC (GMT +0000) - Poll: channel = THREE, refs = 5 +95148941
And the result is:
2007-Jan-06 00:00:04 UTC (GMT +0000) - Poll: channel = TWO, refs = 595 +131400 2007-Jan-06 01:00:06 UTC (GMT +0000) - Poll: channel = TWO, refs = 595 +131400 -------------------------
As the specification is a bit vague, I have chosen to reset the check once I have found two matching items more than 1 hour apart. You will then need again two new entries in the log more than one hour apart to trigger it.

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James