my $infile = "$syslog_dir/$_/messages";
open my $msg_file, '<', $infile or die "couldn't open $infile: $!";
@msg_content = <MSG_FILE>;
Since you're going to work with the file line by line, you should not slurp it into memory as that could fill it up and bring the system down to its knees. Better use something like:
while (<$msg_file>) { do_things; }
And close afterwards (although this is not applicable to this very problem).
With regard to your actual question, I'd follow socketdave's advice and use File::Tail. As for the regex, given that syslog format is a well established one (at least, I'm not aware of any way to customize or localize it), I'd stick some magic values in it:
/^.{7}([\S]{8})/;
|