..I solved the problem..
Good... but why not just use sort just as you have been told previously on this post.
Yes your regexes matched successfully, see

use re 'debug'; @dates = ('20130601', '20130401', '20130501'); my @sorted = map $_->[1], sort { $a->[1] <=> $b->[1] } map [ $_, join('', (/(..)(..)(....)/)[0,1,2]) ], @dates; # DD-MM-YYYY print "@sorted\n";
...produces...
Compiling REx `(..)(..)(....)' size 21 Got 172 bytes for offset annotations. first at 3 1: OPEN1(3) 3: REG_ANY(4) 4: REG_ANY(5) 5: CLOSE1(7) 7: OPEN2(9) 9: REG_ANY(10) 10: REG_ANY(11) 11: CLOSE2(13) 13: OPEN3(15) 15: REG_ANY(16) 16: REG_ANY(17) 17: REG_ANY(18) 18: REG_ANY(19) 19: CLOSE3(21) 21: END(0) minlen 8 Offsets: [21] 1[1] 0[0] 2[1] 3[1] 4[1] 0[0] 5[1] 0[0] 6[1] 7[1] 8[1] 0[0] 9[1] 0 +[0] 10[1] 11[1] 12[1] 13[1] 14[1] 0[0] 15[0] Matching REx `(..)(..)(....)' against `20130601' Setting an EVAL scope, savestack=12 0 <> <20130601> | 1: OPEN1 0 <> <20130601> | 3: REG_ANY 1 <2> <0130601> | 4: REG_ANY 2 <20> <130601> | 5: CLOSE1 2 <20> <130601> | 7: OPEN2 2 <20> <130601> | 9: REG_ANY 3 <201> <30601> | 10: REG_ANY 4 <2013> <0601> | 11: CLOSE2 4 <2013> <0601> | 13: OPEN3 4 <2013> <0601> | 15: REG_ANY 5 <20130> <601> | 16: REG_ANY 6 <201306> <01> | 17: REG_ANY 7 <2013060> <1> | 18: REG_ANY 8 <20130601> <> | 19: CLOSE3 8 <20130601> <> | 21: END Match successful! Matching REx `(..)(..)(....)' against `20130401' Setting an EVAL scope, savestack=12 0 <> <20130401> | 1: OPEN1 0 <> <20130401> | 3: REG_ANY 1 <2> <0130401> | 4: REG_ANY 2 <20> <130401> | 5: CLOSE1 2 <20> <130401> | 7: OPEN2 2 <20> <130401> | 9: REG_ANY 3 <201> <30401> | 10: REG_ANY 4 <2013> <0401> | 11: CLOSE2 4 <2013> <0401> | 13: OPEN3 4 <2013> <0401> | 15: REG_ANY 5 <20130> <401> | 16: REG_ANY 6 <201304> <01> | 17: REG_ANY 7 <2013040> <1> | 18: REG_ANY 8 <20130401> <> | 19: CLOSE3 8 <20130401> <> | 21: END Match successful! Matching REx `(..)(..)(....)' against `20130501' Setting an EVAL scope, savestack=12 0 <> <20130501> | 1: OPEN1 0 <> <20130501> | 3: REG_ANY 1 <2> <0130501> | 4: REG_ANY 2 <20> <130501> | 5: CLOSE1 2 <20> <130501> | 7: OPEN2 2 <20> <130501> | 9: REG_ANY 3 <201> <30501> | 10: REG_ANY 4 <2013> <0501> | 11: CLOSE2 4 <2013> <0501> | 13: OPEN3 4 <2013> <0501> | 15: REG_ANY 5 <20130> <501> | 16: REG_ANY 6 <201305> <01> | 17: REG_ANY 7 <2013050> <1> | 18: REG_ANY 8 <20130501> <> | 19: CLOSE3 8 <20130501> <> | 21: END Match successful! 20130401 20130501 20130601 Freeing REx: `"(..)(..)(....)"'
but even at that it a lot of work.
However, if you must use "Schwartzian transform", you can sort on the month, since the year is the same like this:
use warnings; use strict; my @dates = ('20130601', '20130401', '20130501'); print join ' ' => map{$_->[0]} sort{$a->[1] <=> $b->[1]} map{/.{4}(.{2})/;[$_,$1]} @dates;
But sincerely, for this use sort just like other monks told you.

If you tell me, I'll forget.
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author unknown to me

In reply to Re^3: sorting dates in YYYYMMDD format by 2teez
in thread sorting dates in YYYYMMDD format by learner@perl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.