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; }