my $error = 0; my @tmp = sort datesort qw( 2000-4 2000-2 2000-1 2000-12 2001-1 2002-12 1999-12 ); my($year,$month) = split '-', $tmp[0]; for(my $i = 1; $i < @tmp; $i++) { if(++$month == 13) { $month = 1; $year++; } if($tmp[$i] ne "$year-$month") { print "ERROR! gap at '$year-$month', '$tmp[$i]' found!\n"; $error = 1; last; } } print "Success\n" unless $error; sub datesort { my($a1,$a2) = split '-', $a; my($b1,$b2) = split '-', $b; $a1 <=> $b1 or $a2 <=> $b2; }