use strict; use Time::Local; my $time_str = "2004-06-14 13:34:54"; my ($yr, $mo, $dy, $hr, $mi, $sc) = split( /\D+/, $time_str ); $mo--; # January is supposed to be "month 0" my $time_unx = timelocal( $sc, $mi, $hr, $dy, $mo, $yr ); # the function "does the right thing" given a 4-digit year # (check the Time::Local man page for more details on that) # prove that it works: print "$time_str = $time_unx (" . scalar( localtime $time_unx ) . ")\n";