use POSIX qw(strftime); use strict; use warnings; my @date = localtime; while () { my ($year, $mon, $day, $expected) = split; @date[3,4,5] = ($day, $mon, $year); my $fmt = strftime "%Y%m%d", @date; print "$fmt <=> $expected " . ($fmt eq $expected ? 'matched' : 'failed') . "\n"; } =prints 20110501 <=> 20110501 matched 20110430 <=> 20110430 matched 20110429 <=> 20110429 matched 20110102 <=> 20110102 matched 20110101 <=> 20110101 matched 20110512 <=> 20101231 failed 20110512 <=> 20101230 failed =cut __DATA__ 111 4 1 20110501 111 4 0 20110430 111 4 -1 20110429 111 0 2 20110102 111 0 1 20110101 111 0 0 20101231 111 0 -1 20101230