This might help you get started.
#!/usr/bin/perl
use strict;
my $file_1 = <<END;
chr1 3204562 3661779
chr1 4334223 4350673
chr1 4481008 4486694
chr1 4764014 4775968
chr1 4797773 4836816
chr1 4847574 4887987
chr1 4847574 4887987
chr1 4848208 4887987
chr1 4900049 5009660
chr1 5073053 5152630
END
my @boundary_records;
open( my $file, '<', \$file_1 )
or die( "Error could not open $file_1" );
while( <$file> ) {
push( @boundary_records, [ split( /\s+/ ) ] );
}
close( $file );
my $count = 0;
while( <DATA> ) {
chomp;
my @test_records = split( /\s+/ );
for my $i (@boundary_records) {
if ( $test_records[1] eq $i->[0]
and $test_records[2] > $i->[1]
and $test_records[3] < $i->[2] ) {
$count++;
}
}
print "$_ = $count\n";
$count = 0;
}
__DATA__
Xkr4 chr1 3204562 3661779 - 3 457.217
Rp1 chr1 4334223 4350673 - 4 16.45
Sox17 chr1 4481008 4486694 - 5 5.686
Mrpl15 chr1 4764014 4775968 - 5 11.954
Lypla1 chr1 4797773 4836816 + 9 39.043
Tcea1 chr1 4847574 4887987 + 10 40.413
Tcea1 chr1 4848208 4887987 + 10 39.779
Rgs20 chr1 4900049 5009660 - 5 109.611