my $dhcplog = '/var/log/dhcpd'; my $lastfile = '/var/run/statdhcpcron.last'; my $logfile; open $logfile, '<', $dhcplog; sub setlast { my $last = shift; my $f; open $f, '>', $lastfile or return; print $f $last,$/; # last is first line report($f); # report is the rest of file close $f; } sub getlast { local @ARGV = $lastfile; my $l = <>; # last is first line $l ||= 0; # or start from beginning $l = 0 if $l > -s $logfile; # handle rotate/truncate return $l; } my $last = getlast(); seek $logfile, $last, 0; while (<$logfile>) { # process lines } setlast(tell $logfile); # remember where we stopped close $logfile; # mail report if needed exit; sub report { # returns report based on lines processed }