in reply to Pattern matching for extracting dates

I have reformatted your code to make it more readable:
if ($data=~/(\D{3}) *?(\d{1,2}) *?(\d{4})/) { $month = $datehash{$1}; $day=$2; if ($day=~/\d{1}/) { $day='0'.$day; } $year=$3; $sortingdate=join '', $year, $month, $day; }
Your regular expression is okay, as far as it goes. The error is in the formatting. The test $day=~/\d{1}/ will match every one- or two-digit day specification, so you will always add a zero. Also, do the values of %datehash have leading zeroes where required? Here is how I would re-write your code:
my %datehash; @datehash{ qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec) } = map sprintf( '%02d', $_), 1 .. 12; my $mon_re = join '|', keys %datehash; while ( <DATA> ) { my ( $mon, $day, $year) = /($mon_re)\s+(\d\d?)\s+(\d{4})/; $day = sprintf '%02d', $day; print "$year$datehash{ $mon}$day\n"; } __DATA__ Oct 16 2004 11:09:19:943AM Mar 3 2007 10:30:31:170PM
I have made the regular expression more specific for the month names (since %datehash is already there) and less specific for white space (allowing any, not only blanks).

Anno