Thanks for the suggestion gjb. Does that sort the hash too. I need to sort the dates, find the last date, and perform some calculations later in the script. Also please let me know what qw() is used for.

This doesn't sort the hash, it only converts the date from D/M/YYYY to YYYY/MM/DD so that it can be used as a key in your %datecount hash. This hash can be sorted the way you do it in your code fragment.

You cannot sort a hash : a hash is by construction with no particular order. What you can do is sort the keys of a hash and print the corresponding values.

When you do foreach (keys %hash) you get the keys in an order that is undefined although always the same. But it will change if you add or remove keys, therefore if you need a specific order you should do foreach ( sort { my sort function} keys %hash )