use strict; use warnings; use Time::Piece; my $ctime = Time::Piece->new; my $oldtime = Time::Piece->strptime('Dec 19 17:01:00 2016', '%b %d %T %Y'); print "The current time is $ctime\n"; print "The old time is $oldtime\n"; my $halfago = $ctime - 1800; print "Half an hour ago is $halfago\n"; if ($oldtime > $halfago) { print "Old time is within a half hour\n"; } else { print "Old time is outside a half hour\n"; } #### The current time is Mon Dec 19 17:07:06 2016 The old time is Mon Dec 19 17:01:00 2016 Half an hour ago is Mon Dec 19 16:37:06 2016 Old time is outside a half hour