There are two reasons why your script is slow:
- You are using Date::Manip to parse the date strings of every record. Date::Manip is very slow.
- As mentioned by somebody else - you are scanning all log entries at every invocation. Putting this together with the fact that every log entry is parsed using Date::Manip, and you have the perfect recipe for turtle-sickness. Instead of rescanning and skipping log entries before a certain cut-off time, maintain an offset into the file of the 'last log entry processed' and use the seek() system call to resume from where you left off. If possible, avoid Date::Manip or any time processing completely as it will often result in unnecessary system calls, or else CPU intensive processing.
Also mentioned by somebody else: monks love to help other monks. However, monks do not like to have their freely offered gifts abused. You do need to do your own research once in a while, and you do need to think of monks as more than a resource that can be exploited to allow you to get your job done without thinking for yourself. This comment is not made with disrespect towards you. It is made as a request that the valuable resource known as 'the monks' is respected.