in reply to confusing number of elements in an array

$index gets reset to zero before the final loop. Notice that your calls to sorter() occur in the code before the assignment to $index.

Moving your code around will help. A better idea is to use native iteration, though, as you don't use the array index:

for my $seq (@$allSeq) { print "seq -->$seq\n"; }

(As a style note, I spent a lot of time deciphering your code; using variable names in your subroutines for parameters would really help. Also, I find it much easier to call subs by reference with the $subref->( @args ) syntax; it's much less visually cluttered.)

Update: ikegami pointed out a typo.