You could use Date::Calc's Days_in_Month function (or any
other function that will tell you how many days there are
in the current month) and code as follows:
if(($cur_day+7) > Days_in_Month($cur_year,$cur_month)){
# its the last n-day of the month 'cause this day next week is in
+next month
}