my @hours; while ( <$file> ) { my $hour = ( localtime )[ 2 ]; if ( /(job-id-format) failed/ ) { if ( ! exists $failed{ $1 } ) { push @{ $hours[ $hour ] }, $1; failed{ $1 } = 1; } report_temporary_job_failure( $1 ); } elsif ( /(job-id-format) succeeded/ ) { delete $failed{ $1 } if exists $failed{ $1 }; report_previously_failed_job_success( $1 ); } if ( 0 == $. % 100 ) { my $purge = ( $hour - 8 >= 0 ) ? $hour - 8 : $hour + 24 - 8; while ( $job = shift @{ $hours[ $purge ] } ) { report_final_job_failure( $job ); delete $failed{ $job }; } } }