#!/usr/bin/perl use strict; use warnings; use Date::Calc qw/Localtime Days_in_Month/; sub give_dates { my ($year, $month, $day) = (Localtime())[0,1,2]; my $days_in_mon = Days_in_Month($year, $month); my $cutoff = int($days_in_mon / 2); my ($start, $end); if ( $day <= $cutoff) { # First half of month $start = $year . sprintf("%02d", $month) . '01'; $end = $year . sprintf("%02d", $month) . $cutoff; } else { # Second half of month $start = $year . sprintf("%02d", $month) . $cutoff; $end = $year . sprintf("%02d", $month) . $days_in_mon; } return ($start, $end); } print join " ", give_dates(), "\n";