#!/usr/bin/perl -w use strict; use Data::Dumper; use autodie; my $file2text = <) { my @file2_cols = split; push @{$file2{$file2_cols[1]}}, [@file2_cols]; } #print Dumper \%file2; while () { 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