in reply to for loop syntax ...
In the first case the loop iterates 9 times and the substitution operates on $_, which is not the loop variable because $i is supplied.
In the second case the loop iterates 9 times and the substitutions operates on $_ which is the loop variable and takes the values 1 - 9 on successive passes through the loop (no loop variable supplied).
The behaviour of the second form can be made the same as the first by providing a loop variable:
for my $i (1..9) {s/\s/;/;}
|
|---|