for (my $i = 0; $i <= 4; $i++) { my $j=0; while (my $line = readline(SORTD)) { $j++; my $number = substr($line, $j*2, 2); } }