foreach $hour ( @hourRange ) { $timeBlock = $timeDateBase . $hour; print "$timeBlock\n"; while( ) { chomp; if( $_ =~ /$timeBlock/ ) { print "$timeBlock\n"; ( $a, $b, $c ) = split( /"/, $_ ); if( $a =~ /^(\S+)\s-\s-\s\[(\S+)\s/ ) { $IP = $1; $timeString = $2; print "$IP\n"; print "$timeString\n"; } } } } #### foreach my $hour ( @hourRange ) { my $timeBlock = $timeDateBase . $hour; print "$timeBlock\n"; seek LOG, 0, 0; ## <== seek to the begin of LOG while( ) { chomp; if( $_ =~ /\Q$timeBlock\E/ ) { print "$timeBlock\n"; my($a) = split( /"/, $_ ); ## <== only used $a if( $a =~ /^(\S+)\s-\s-\s\[(\S+)\s/ ) { my $IP = $1; my $timeString = $2; print "$IP\n"; print "$timeString\n"; } } } }