... # Read the last 2 lines of a log file my $log = "log.log"; # if this file is still empty by the time the code runs. my $line = do { open my $line, '-|', tail => -2, $log or die "Can't spawn tail: $!\n"; <$line>; }; $line =~ s/[\r\n]+$//; my $show = ''; # <<<< happens here, uninitialized value if ($line =~ /(\bTest\b\s+.+\s+\baccount\b)?/) { #<<<< happens here, uninitialized value $show = $1 || ''; } ...