@ARGV or die "No input file specified"; open my $first, '<',$ARGV[0] or die "Unable to open input file: $!"; open my $second,'<', $ARGV[1] or die "Unable to open input file: $!"; print scalar (<$first>); while(<$second>){ chomp; @line=split /\s+/; $hash{$line[2]}=$line[3]; } while (<$first>) { @cols = split /\s+/; $p1 = $cols[4]; $p2 = $cols[5]; foreach $key (sort keys %hash){ if ($p1>= "$key"){ if ($p2<=$hash{$key}) { print join("\t",@cols),"\n"; } } else{next;} } }