I thought that I would post a possible solution (using the module Set::IntSpan). It eliminates making the logic to detect overlap by testing for set intersection between the spans in the cnv file and the spans in the genelist* files. For each line in the genelist file, it checks to see if it intersects with any/all lines in the cnv file.

However, this may not be what you were looking for as far as output/results. :-(

Hoping this is something like you were asking. The same genename overlapped with both spans in the cnv file for all of the genenames except for the last one, NR3C1. It overlapped with the span in the cnv file with size=64547 but not with the span with size=3567

Thanks Chris. This also makes a bit of sense. Its great if the same gene overlaps with both spans in the cnv file. Let me try and run this with my gene list which is much larger and see if this works or not. As for my previous code.. I fixed a few things but I think it is something to do with my sub function. I am working on fixing that.