in reply to How to use __DATA__ efficiently, help!

What Tommy just said. This the Wrong Way™ to do it. That said, I do exactly this sometimes with Template by using named blocks. Here's a runnable example-

use warnings; use strict; use Template; use CGI qw( header ); print header(); my $tt2 = Template->new( TRIM => 1 ); my @actions = qw( foo bar ); my @titles = ( "O HAI", "O NOES", "KTHXBAI" ); $tt2->process(\*DATA, { title => $titles[rand@titles], my_action => $actions[rand @actions], }) or warn $tt2->error; __DATA__ [%~BLOCK foo %] This is my foo. There are many foos like it but this one is mine. [%~END %] [%~BLOCK bar %] This is my barbaz. This is my qux. This is for coding, this is for... +uh... [%~END %] [%~# TEMPLATE ----------%] <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" / +> <title>[% title | html %]</title> </head> <body> <header> <h1>[% title | html %]</h1> </header> <article> [% PROCESS $my_action %] <aside>Action: [% my_action | html %]</aside> </article> <footer> <small> License: <a itemprop="license" href="http://perlfoundation.org/artistic_license_2_0">Artistic 2.0</a +> </small> </footer> </body> </html>