Q:

How to compare "Fri Jul 1 05:21:23 2016" datetime format in perl

I have a datetime value in the format "Fri Jul  1 05:21:23 2016", how can i compare this?
I need to do like if($date1<$date2) { print "do something"! }
Kindly help to find the answer!

A:

You could use DateTime::Format::Strptime to parse the strings into Datetime objects that support comparisons:
use strict;
use warnings;
use feature 'say';
use DateTime::Format::Strptime;

my $strp = DateTime::Format::Strptime->new(pattern => '%a %b %d %H:%M:%S %Y');

my $dt1 = $strp->parse_datetime("Fri Jul 1 05:21:23 2016");
my $dt2 = $strp->parse_datetime("Sat Jul 2 05:21:23 2016");    

if ($dt1 < $dt2) {  # or use DateTime->compare()
    say '$dt1 < $dt2';
}
elsif ($dt1 == $dt2) {
    say '$dt1 == $dt2';
}
else {
    say '$dt1 > $dt2';
}

