in reply to warning "Out of memory!"
I agree with others that your posted code definitely looks like its missing quite bit.
In your code, I see lines like my @genes=<GENES>;, which kind looks like your intent is to store the contents into an array such that each element of the array corresponds to a line in the file.
Don't know if that is the source of your memory issues or not, but if that really is your intent and you want to reduce the memory being used, I would recommend checking out Tie::File. Tie::File will tie a file to an array and each line of the file becomes an element of the array. Also, Tie::File does not read the entire file into memory. It even has an option that you can set to increase/decrease the amount of memory that it "will consume at any time while managing the file".