sub tmpl { my $usrid = get_my_userid(); my $text; local $/; local *D; my ($dat, $hashref) = @_; open(D, $_[0]) || die $!; $text = ; close(D); $hashref->{sid} = $sessionid unless $hashref->{sid}; $hashref->{username} = $usrid; chop($text); $text =~ s{ %% ( .*? ) %% } { exists( $hashref->{$1} ) ? $hashref->{$1} : "" }gsex; return "Content-Type: text/html\n\n$text" if $hashref->{header} == 1; return $text; } print tmpl('/usr/local.../page', {header=>1});