my @timeSlots; my $concurrent = 0; my $lastTimeSlot = 0; while( <$log> ) { my( $time, $type ) = m[(...).+(Start|End)]; ++$concurrent if $type eq 'Start'; --$concurrent if $type eq 'End'; my $timeSlot = timeToTimeslot( $time ); push @timeSlots, ( $concurrent ) x ( $timeSlot - $lastTimeSlot ); $lastTimeSlot = $timeSlot; ## Do stuff to build your intspan objects ... }