use strict; use warnings; open my $logFH, q{<}, \ < ) ) { next unless $line =~ m{(?x) ^ Script \s \S+ \s invoked \s by \s root \s at \s $rxDate (?: \s $rxTime )? }; my $date = $1; my $time = defined $2 ? $2 : do { defined( $line = <$logFH> ) or die qq{Unexpected EOF\n}; $line =~ $rxTime ? $1 : q{No time found}; }; my $timestamp = join q{ }, $date, $time; print qq{Timestamp: $timestamp\n}; } close $logFH or die qq{close: <