in reply to sorting dates in YYYYMMDD format

On of the great things about YYYYMMDD is that if you sort it numerically you get it properly sorted. So just do

@ordered = sort { $a <=> $b } @dates;

Comment: your expected output is as wrong as your output you get, they are identical... And in your code, $d is never defined. And the example is badly chosen as all parts are identical apart from the month. In this case, it does not matter, whether year is at the beginning or at the end.

UPDATE: Even if you sort string-wise you are fine, so sort @dates does the job.