in reply to Sort and Substitution

For one thing you don't need the '$x' counter in your for loop, and for another you don't need a regex when substr will do:
$count='000001'; substr($_,0,6)=$count++ for @ordered;