Making a file2 into a HashofArray keyed on this main link between the two files (H,9) narrows down the number of rows to search for a match. Your HoHoH is unnecessary complexity and there is no need for sorting.
#!/usr/bin/perl -w use strict; use Data::Dumper; use autodie; my $file2text = <<END; 97486 H 262 279 67486 9 118 119 87486 9 183 185 248233 9 124 134 END open my $fh2, '<', \$file2text; my %file2; #this is a HashofArray (HoA) while (<$fh2>) { my @file2_cols = split; push @{$file2{$file2_cols[1]}}, [@file2_cols]; } #print Dumper \%file2; while (<DATA>) { chomp; my ($link, $low_limit, $high_limit) = (split)[2,4,5]; next unless exists $file2{$link}; foreach my $row_ref (@{$file2{$link}}) { if ( ($row_ref->[2] <= $low_limit) and ($row_ref->[3] >= $high_limit) ) { print "$_ $row_ref->[0]\n"; } } } =prints 101_#2 1 H F0 263 278 2 1.5 97486 103_#1 2 9 V2 124 134 1 1.3 248233 =cut __DATA__ 101_#2 1 H F0 263 278 2 1.5 102_#1 1 6 F1 766 781 1 1.0 103_#1 2 15 V1 526 581 1 0.0 103_#1 2 9 V2 124 134 1 1.3 104_#1 1 12 V3 137 172 1 1.0 105_#1 1 17 F2 766 771 1 1.0

In reply to Re: Using perl hash for comparing columns of 2 files by Marshall
in thread Using perl hash for comparing columns of 2 files by vikas.bansal

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.