in reply to need help on declaring variables

The line
my $dt = $Strp->parse_datetime($1);
is returning undef because the input string in $1 is in an incorrect format. Either change the declaration of Strp like
my $Strp = new DateTime::Format::Strptime(pattern => '%Y-%b-%d %T' +, on_error => 'croak');
to throw an error in that case or check for it in your code by replacing the line starting 'my $dt...' with
unless (my $dt = $Strp->parse_datetime($1)) { warn "invalid datetime: $1"; next; }