use strict; use warnings; open my $m, '<', 'mapped.txt' or die 'Cannot open mapped.txt'; while (<$m>) { chomp; my @l = split /\|/; open my $p, '<', 'ptt.txt' or die 'Cannot open ptt.txt'; while (<$p>) { next if /^Location/; chomp; my ($range) = split; my ($fm, $to) = split(/\.\./, $range); if ($l[1] >= $fm and $l[1] <= $to) { # here you can set which column is used to compare print "$l[1] - $_\n"; } } close $p; } close $m;