use warnings; use strict; my $currentDate = `date +%Y%m%d`; my $logPath = "/dhcp/logs" my $logFile = "{$path}/DHCPD.log.{$currentDate}" my @tail = qx(tail -f -1 $logFile | grep $_); if (@tail) { print @slice = @tail[0 - 2]; last; } else { print "not found"; }