If the template is very small, probably the most efficient method is to print directly:
print <<OUT; First line! This line has a $var in it. Second line... Thanks for reading this! OUT
If your template is large but has only a few insertion points, you can read the file into a string and use index or rindex:
use strict; use warnings; my ($handle, $text, $insert); open($handle, 'template.txt'); read($handle, $text, 10000); close($handle); $insert = index($text, '<!-- INSERT -->'); print substr($text, 0, $insert); print 'My inserted data goes here!'; print substr($text, $insert);
Beyond that, a formal templating system or module is probably best, or you can always use PHP, which is designed for embedding in pages:
Blah blah blah I'm inserting a variable here: <?php echo $var; ?> And again here: <?php echo $another; ?>
I still like using PHP for simple things.

In reply to Re: Efficiency/Speed question... (files or formats?) by TedPride
in thread Efficiency/Speed question... (files or formats?) by Spidy

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.