#!/usr/bin/perl; use warnings; use strict; # I am not sure what data set you have? # yyyy-mm-dd will sort in ASCII order # with a simple sort. # yyyy-dd-mm or mm-dd-yyyy is a bit more # complex, eg: 2013-11-07 vs 11-07-2013. # It is possible to detect yyyy-mm-dd # versus yyyy-dd-mm or mm-dd-yyyy, however # dd vs mm can be quite problematic. # 02-03-2011 vs 03-02-2011? # the code that you show is actually rather # strange looking. what are your trying to do? show some input and expected output.