in reply to For- loop increment not passing to inner block

By 'inner block' do you mean this:
while (my $line = readline(SORTD)) { my $number = substr($line, $i*2, 2); }
If so, I don't see where you are incrementing $i.

The way the for loop works is that $i will not be incremented until the end of the for block is encountered, so $i is not going to be incremented inside the while loop unless you explicitly do it yourself.