Here's a way without external modules that I think does what you want. It does so by setting up a month to month num hash, and then after collecting all of the month names, get the unique ones, then sort them based on their month number in the $month_names hash:

use warnings; use strict; use Data::Dumper; my %month_names = ( January => 1, February => 2, March => 3, April => 4, May => 5, June => 6, July => 7, August => 8, September => 9, October => 10, November => 11, December => 12, ); my @months; while (<DATA>) { my ($client, $rest) = split /\|/; $rest =~ s/\s+//g; push @months, split /\d+/, $rest; } @months = uniq(@months); @months = sort { $month_names{$a} <=> $month_names{$b} } @months; print Dumper \@months; sub uniq { my %seen; grep ! $seen{$_}++, @_; } __DATA__ IBM | February 1 March 5 July 4 Oracle| January 3 March 4 April 6 May 5 RedHat | March 2 June 3 August 1

Output:

$VAR1 = [ 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August' ];

In reply to Re^3: How to print months in proper order from array by stevieb
in thread How to print months in proper order from array by dirtdog

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.