in reply to comparing dates

This is somewhat unrelated to your question, but I noticed this line:
open (DATABASE, "$filename" || &ErrorMessage);
This only gives an error message if $filename isn't true. What you probably meant was
open (DATABASE, "$filename") || &ErrorMessage;
which gives an error message when the file couldn't be opened.