I want to use $#array. But # makes the next words commented. Is it possible to avoid such situation?

for ($i =0; $i <= $#array; ++$i)

No it doesn't, that's just you're editor's highlighting. If you don't want to see that then use < scalar(@array) rather than <= $#array

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.