If your "array" is %names, that isn't an array in Perl's terminology; it's a hash; what PHP calls an "associative array."
And hashes do NOT maintain their input order (without the likes of Tie::Hash. If it's perl (nod to Vicar 1nickt, above) you're using, you might consider that. But first, read some of the help about arrays and hashes you'll find here... in Tutorials or Super Search and perhaps even read perldoc perltie (from your CLI).
And does the select part of line 1 means you're trying to print something pulled from a db? If so, Super Search and the Tutorials should also offer assistance.