in reply to execution of command inside for loop fails
I see "i++" instead of "$i++". I would suggest using foreach loop in such cases, no need for a loop variable.
UPDATE: Please next time also add a description of how it is not working. You'll get much better answers that way
In Section
Seekers of Perl Wisdom