print <<'END'; \documentclass{article} \usepackage{graphicx} \usepackage{fullpage} \begin{document} END #### sub substitute_vars { my ($template, $hash) = @_; (my $out = $template) =~ s/\${([^}]+)}/$$hash{$1}/ge; $out; } #### my $template = <<'TEMPLATE_END'; \section{${imfile}} \begin{figure}[!hbp] \centerline{\includegraphics[width=9cm, height=9cm]{ims/${imfile}_gd.png}} \end{figure} \begin{figure}[!hbp] \centerline{\includegraphics[width=12cm, height=9cm]{${imfile}mfm.png}} \end{figure} \newpage TEMPLATE_END for (@text) { chomp; print substitute_vars($template, { imfile => $_ } ); } #### \newcommand{\insert_figures}[1]{ \section{#1} ... \centerline{\includegraphics[width=9cm, height=9cm]{ims/#1_gd.png}} ... \centerline{\includegraphics[width=12cm, height=9cm]{#1mfm.png}} ... \newpage }