Use time to get the current epoch seconds Use localtime to convert that to date/time If the date is greater than 21 then increment the month number end set the date to 21 and the time to 12am use Time::Local::timelocal to convert that time to epoch seconds Subtract that from your first number