I assume that your problem lies within the regular expression and not in the CGI-handling, although your question dosen't really make that clear.

I'm taking this regular expression ("RE") from an old shell script called sitemap which did a site map in bash and some GNU tools - you might want to read more on regular expressions in perlre...

# for offline conversion, set this to 1 $offline = 0; undef $/; open( FILE, "< $filename" ) or die "Can't open $filename : $!\n"; $HTML = <FILE>; close FILE; # Note that you can use \2 (or $2) in the new title part # to reference the old title. $HTML =~ s!(.*?<TITLE>)(.*?)(</TITLE>.*)!... new title here ...!ims; ($Left, $Title, $Right) = ($1,$2,$3); # Here, $Left contains everything left of the page title # $Right contains everything right of the page title # and $Title contains the page title # here you could do some more magic to the page title # before assigning it back to $HTML ... if ($offline) { rename $filename, "$filename.backup"; open( FILE, "> $filename" ) or die "Can't create $filename : $!\n" +; print FILE $HTML; close FILE; } else { print FILE; };

As you might (or might not) notice, this code will have problems with malformed HTML or a document that contains two TITLE tags, only the first such tag will get handled. Also, if you have a commented-out TITLE tag, this will also confuse the RE. But as you say that you want to use this in a template, you can craft your template around that, I hope :)


In reply to HTML title substitution by Corion
in thread title sub by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.