my $present_month = ( localtime() )[4] + 1; print sprintf "current month: %d\nprevious month: %d\n", $present_month, $present_month - 1;