Well, the most common problem when sorting text that contains numbers is that values with different numbers of digits don't sort numerically. Here is one way to fix that. Here is another:

my @data= qw( 953-FMT-FMT 954-FMT-FMT BLOGO93-FMT-FMT 955-FMT-FMT BOXSTART2-FMT-FMT BOXEND2-FMT-FMT 956-FMT-FMT 413-FMT-FMT DATE1-FMT-FMT 414-FMT-FMT 415-FMT-FMT 416-FMT-FMT BLOGO107-FMT-FMT 417-FMT-FMT 419-FMT-FMT 418-FMT-FMT BLOGO63-FMT-FMT 393-FMT-FMT 394-FMT-FMT BLOGO75-FMT-FMT 420-FMT-FMT 421-FMT-FMT 395-FMT-FMT ); my %data; foreach my $data ( @data ) { ( my $sort= $data ) =~ s/(0*)(\d+)/ pack("C",length($2)) . $1 . $2 /ge; $data{$sort}= $data; } print join( "\n", @data{ sort keys %data } ), "\n";
which produces
393-FMT-FMT 394-FMT-FMT 395-FMT-FMT 413-FMT-FMT 414-FMT-FMT 415-FMT-FMT 416-FMT-FMT 417-FMT-FMT 418-FMT-FMT 419-FMT-FMT 420-FMT-FMT 421-FMT-FMT 953-FMT-FMT 954-FMT-FMT 955-FMT-FMT 956-FMT-FMT BLOGO63-FMT-FMT BLOGO75-FMT-FMT BLOGO93-FMT-FMT BLOGO107-FMT-FMT BOXEND2-FMT-FMT BOXSTART2-FMT-FMT DATE1-FMT-FMT
note how "BLOGO107" comes after "BLOGO93".

If you also want "BLOGO" to sort last, then either separate those beforehand as already mentioned or try this:

my @data= qw( 953-FMT-FMT 954-FMT-FMT BLOGO93-FMT-FMT 955-FMT-FMT BOXSTART2-FMT-FMT BOXEND2-FMT-FMT 956-FMT-FMT 413-FMT-FMT DATE1-FMT-FMT 414-FMT-FMT 415-FMT-FMT 416-FMT-FMT BLOGO107-FMT-FMT 417-FMT-FMT 419-FMT-FMT 418-FMT-FMT BLOGO63-FMT-FMT 393-FMT-FMT 394-FMT-FMT BLOGO75-FMT-FMT 420-FMT-FMT 421-FMT-FMT 395-FMT-FMT ); my %data; foreach my $data ( @data ) { ( my $sort= $data ) =~ s/(0*)(\d+)/ pack("C",length($2)) . $1 . $2 /ge; $sort =~ s/^BLOGO/~BLOGO/; $data{$sort}= $data; } print join( "\n", @data{ sort keys %data } ), "\n";

        - tye (but my friends call me "Tye")

In reply to (tye)Re: sort on numbers embedded in text by tye
in thread sort on numbers embedded in text by d4vis

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.