my @bits = split ' ', localtime( time() - ( 45 * 24 * 60 * 60 ) );; my $n = 1; my %months = map{$_, $n++} qw[Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec];; my $targetDate = join '-', $bits[ 4 ], $months{ $bits[ 1 ] }, $bits[2];; print $targetDate;; 2007-11-28 #### open OLDDB, '<', $dbname or die ...; open NEWDB, '>', $tempfile or die ...; open ARCHIVE, '>>', $archive or die ...; print ARCHIVE while defined( $_ = ) and substr( $_, -17, 10 ) lt $targetDate; print NEWDB; ## Output first 'failing' record to newdb print NEWDB while ; close for OLDDB, NEWDB, ARCHIVE; unlink $dbname; rename $tempfile, $dbname;