my %range_counts = (); my %counts = (); while( $entire_file =~ m/(\d+)bn(\d+), bytes/sg ) { $range_counts{'4kset'} ++ if $2 > 4000 and $2 < 6000; $counts{$2} ++ if $2 > 4000 and $2 < 6000; } print "there were $counts{'4kset'} 4000-6000 lines\n";