sub resetFilePos { my $fileno = shift; my $mtime_curr = (stat($fileno))[9]; my $mtime_new = (stat($file_name))[9]; if ($mtime_curr + 5 <= $mtime_new) { close($fileno); open($fileno, "<",$file_name ) or die "Can't open file $file_name"; } else { seek($fileno,0,1); } return $fileno; } sub process { my $file = "/$ENV{HOME}/Error.log"; eval { open ($tail,"<",$file_name) or die "Can't open file $file_name"; for(;;) { for $line (<$tail>) { if ( /OutOfMemoryError/) { send_mail($_,$.); } } $tail = resetFilePos($tail); } close($tail); } } process();