in reply to warning "Out of memory!"

Did you use strict; and use warnings;?

Which is the starting value of $index? From that piece of code, it seems to be undef, which is not a valid index for @proteome array.

At the other end, it seems that $index is going out of the array. Change the condition of the last until to $index >= @proteome... The same for other until condition.

Just guessing without the input file specs...