# my code above, as a function sub lastday_time { use Time::Local; # I never do this in real code # I put module uses at the top of # the entire program, not each sub # arguments are assumed to be in "human" terms my ($m, $y) = @_; $m--, $y -= 1900; # perl-ify them my ($nm, $ny) = ($m == 11) ? (0,$y+1) : ($m+1,$y); # return the first of next month, minus one day return timelocal(0,0,12, 1,$nm,$ny) - 86400; } sub is_last_of_month { # arguments are "human" # lastday_time() subtracts 1 from $m and 1900 from $y my ($d, $m, $y) = @_; my $last_day = (localtime lastday_time($m,$y))[3]; # fixed that last line -- I had $d, meant $m return $d == $last_day; }