use strict; use warnings; my %hash = ( "a" => "abc", "d" => "def", "g" => "ghi" ); my $text = "%a% %d% %g%"; print "Before: $text\n"; print "After : ", fillTemplate($text, \%hash), "\n"; sub fillTemplate { my ($text, $hash) = @_; $text =~ s/%(\w)%/$hash->{$1}/g; return $text; } #### using System; using System.Collections; using System.Text.RegularExpressions; class test { static Hashtable hash = new Hashtable(); static void Main () { hash.Add("a", "abc"); hash.Add("d", "def"); hash.Add("g", "ghi"); string text = "%a% %d% %g%"; Console.WriteLine( "Before: {0}", text ); Console.WriteLine( "After : {0}", fillTemplate( text ) ); } static string fillTemplate ( string text ) { return Regex.Replace( text, @"%(?\w)%", new MatchEvaluator( hashLookup ) ); } static string hashLookup ( Match m ) { return (string)hash[m.Groups["templ"].Value]; } }