$VAR1 = { '200210014 200210105' => [ "ABC Corp. / 1 / some text description", "XYZ Ltd. / 1 / some text description", "CDC Inc. / 1 / some text description", ], '200211011 200212053' => [ "ABC Corp. / 2 / some text description", "XYZ Ltd. / 2 / some text description", ], '200323021 200331234' => [ "ABC Corp. / 3 / some text description", ], etc... } #### while () { my ($key2,$data) = split(/,/, $_, 2); # use grep to do the "join": my @match_keys = grep { my ($sid,$eid) = split(/ /,$_); $key2 >= $sid and $key2 <= $eid } keys %VAR1; foreach my $matched_range ( @match_keys ) { my @matched_data = @{$VAR1{$matched_range}}; # do something with @matched_data } }