#!/usr/bin/perl use strict; my %hash; while( ) { chomp; my( $name, @times ) = split; # convert each time to [ date, time bin ] @times = map { [ date($_), time_bin( $_ ) ] } @times; =pod The multi-level hash looks like this: $hash{ date }{ time bin }{ queue name }{'running'} {'queued'} Look at it with: use Data::Dumper; print Dumper( \%hash ); =cut # count the bin it was queued, even if it runs in that bin $hash{ $times[0][0] }{ $times[0][1] }{ $name }{'queued'}++; # count the bin it starts running $hash{ $times[1][0] }{ $times[1][1] }{ $name }{'running'}++; # count the bin it ended, unless it's the same bin it started # might want to check that it starts and ends on the same date too $hash{ $times[2][0] }{ $times[2][1] }{ $name }{'running'}++ if $times[1][1] ne $times[2][1]; }