#!/usr/bin/perl -w use strict; my($emltmpl) = './email_template'; my($parser) = qr/(?s)(?:\%){3}(.*?)(?:\%){3}/; my(%tokens) = ( 'date' => scalar(localtime), 'fname' => 'André', 'lname' => 'Cameron', 'street' => '123 Foo Bar Drive', 'zip' => '54321', 'state' => 'OZ', 'city' => 'Emerald City', 'orderid' => 'S8d65adPA-5', 'product' => 'widget', 'price' => '$9.95 USD', 'quantity' => 2, 'subtot' => '$19.90 USD', 's&h' => '$2.00 USD', 'tax' => 'n/a', 'total' => '$21.90 USD', ); { local($/); local(*FH); open(FH, $emltmpl) or die(qq[Can't open "$emltmpl" $!]); $emltmpl = ; close(FH); } sub expand_tokens { $_[0] =~ s/$parser/$tokens{$1||''}/gme; $_[0] } print(expand_tokens($emltmpl)); __END__ TO TRY OUT THIS EXAMPLE, create a new file in the same directory where you run this script. Name the new file "email_template" and copy the text below _this line_ into the file, and then run this code. %%%date%%% Hello %%%fname%%%, Thanks for buying a %%%product%%%. The order ID for this purchase appears below. Should you have questions regarding this order, please direct your inquiries to WWWidget support and include your order ID. Order ID: %%%orderid%%% As per your request, your %%%product%%% will be shipped to: %%%fname%%% %%%lname%%% %%%street%%% %%%city%%%, %%%state%%% %%%zip%%% Details of your purchase: item %%%product%%% %%%price%%% (%%%quantity%%% count) subtotal %%%subtot%%% s&h %%%s&h%%% tax %%%tax%%% _______________________ total %%%total%%% Regards, The WWWidget Store Ô¿Ô¬