Help for this page
$page =~ s/(%TABLE{.*?name\=\"History[^"]*"[^}]*}%\s*(\|[^\|]*){3}\|\s +)((\|[^\|]*){3}\|\s)*/$table/eo;