#! perl -slw use strict; use Data::Dump qw[ pp ]; my @data; while( ) { my( $col, $cnt, $stat, $miss, $mod ) = m[ ^ Collection=>(\d+) \s+ ImageCount=>(\d+) \s+ Status=>(\w+ ) \s+ Missing=>( [1-9,]+ )? \s+ Modified=>( .+ ) $ ]x or warn "Bad format at line $.\n" and next; my( $day, $mon, $year, $hrs, $min, $sec ) = $mod =~ m[(\d+)/(\d+)/(\d+) (\d+):(\d+):(\d+)] or warn "Bad date format in line $." and next; push @data, { Collection => $col, ImageCount => $cnt, Status => $stat, Missing => [ split ',', $miss||'' ], Modified => sprintf( "%4d/%02d/%02d %02d:%02d:%02d", $year, $mon, $day, $hrs, $min, $sec ), }; } ##pp 'original order', \@data; ## Sort data by image count descending and modified date ascending my @ordered = sort { $data[ $b ]{ ImageCount } <=> $data[ $a ]{ ImageCount } || $data[ $a ]{ Modified } cmp $data[ $b ]{ Modified } } 0 .. $#data; print 'Sorted by Image count descending and modified date ascending'; pp $data[ $_ ] for @ordered; __DATA__ Collection=>168245 ImageCount=>6 Status=>SI Missing=>1,3 Modified=>01/18/2012 11:14:30 Collection=>161745 ImageCount=>6 Status=>I Missing=>2,3 Modified=>01/18/2012 11:16:38 Collection=>162451 ImageCount=>6 Status=>SC Missing=> Modified=>01/20/2012 11:16:38 Collection=>117481 ImageCount=>8 Status=>C Missing=> Modified=>01/18/2011 7:16:38