It doesn't exactly answer your question, but if you're dealing with regions you may want to have a look to bedtools:
$ bedtools intersect -a file1.bed -b file2.bed -wa
SpoScf_15890 12 2376
SpoScf_07684 10 4075
SpoScf_07684 64 4276
Super_scaffold_60 74732 78743
Super_scaffold_60 74955 77543
As I said, this doesn't answer your question since this tool looks for overlaps rather than positions-less-than conditions, but it does allow you to think about a faster and more eficient way of handling region information. Having said this, and although it's not the most efficient way to answer your second question with the "but not more than 1000 (1K)" condition, you can still solve it with bedtools:
$ perl -lane 'foreach $i (1,2) { print join "\t", $F[0], $F[$i]-1, $F[$i], (join " ", @F) }' file1.bed > file1.bed.temp
$ perl -lane 'foreach $i (1,2) { if ($F[$i] > 1000) { $t = $F[$i] - 1001 } else { $t = 0 } print join "\t", $F[0], $t, $F[$i] }' file2.bed > file2.bed.temp
$ bedtools intersect -a file1.bed.temp -b file2.bed.temp -wa | cut -f4 | sort | uniq -c | perl -lane 'print join "\t", @F[1..3] if $F[0] == 2'
SpoScf_07684 10 4075
So a match between the files is:
What if one column entry is larger and the other smaller? Is this possible?
Only less than, or less than and equal to?
Thanks to you! Both scripts work well.
I would like to add one more condition if it is possible for you to edit the script. Another condition: Column 2 of file 1 is less than column 2 of file2 "but not more than 1000 (1K)" and also Column 3 of file 1 is less than column 3 of file2 "but not more than 1000 (1K)?
Please refrain from adding new questions as answers - they should be comments. I have moved them this time.
It is also generally bad practice/forum etiquette to continually ask for modifications and updates to the original question as it muddles the information for future users who might need to learn from this thread.