in reply to for loop syntax ...

There is a difference between your two loops.

for (my $i = 1; $i <= 9; $i++) { s/\s/;/; }

In this loop, the variable $i goes from 1 to 9 and each time round the loop the variable $_ has a substitution applied to it.

for (1..9) { s/\s/;/; }

In this loop, you don't have $i so $_ is used as the iterator variable. So when you apply the substitution to $_ you are applying it to the numbers 1 to 9.

I think that you were looking for this:

for my $i (1..9) { s/\s/;/; }

which does the same thing as your first loop.

I have a nagging feeling that this may be an XY Question and that perhaps you should explain what you're really trying to do.

--

See the Copyright notice on my home node.

"The first rule of Perl club is you do not talk about Perl club." -- Chip Salzenberg