$ cat t.pl #!/usr/bin/perl use strict; use warnings; use feature ':5.10'; my %Variables = ( NAME=>'Roboticus', STATE=>'KY', BIRD=>'Cardinal' ); my $Template = '{NAME} lives in {STATE}. {FOO}.'; for my $t ($Template=~m/{([A-Z]+)}/g) { $Template =~ s/{$t}/$Variables{$t}/g if exists $Variables{$t}; } say $Template; $ perl t.pl Roboticus lives in KY. {FOO}.