#!/usr/bin/perl -w use strict; use CGI; # Initialize CGI variable my $q = new CGI; # Load HTML my $html; { local $/; $html = ; } # Format HTML using data callbacks $html =~ s/%%(\w+)%%/&FormatHTML($1)/ge; # Display the HTML print $q->header, $html; exit(0); sub FormatHTML() { my $tag = shift; if ($tag eq "TITLE") { return &FormatTitle(); } elsif ($tag eq "TOC") { return &FormatToc(); } elsif ($tag eq "BODY") { return &FormatBody(); } } sub FormatTitle() { return "HTML Sample"; } sub FormatToc() { return "Table of Contents
"; } sub FormatBody() { return "Sample text"; } __DATA__ %%TITLE%% %%TOC%% %%BODY%%