my %act1 = ( "food" => "eat it", "drink" => "drink it", "Perl" => "play it"); my %act2 = ( "food" => "prepare it", "drink" => "be drunk", "Perl" => "write it"); my %actions = ( act1 => \%act1, act2 => \%act2, ); my %vars = ( item => \$item, ); my $out = '-p $act1{$item} -p $act2{$item} -p ... '; # resp. read that one from a file # The world's simpled templating system: $out =~ s-\$(\w+) # the name of the hash (%act1) \{ # opening brace \$(\w+) # the name of the variable to be used ($item) \} # closing brace - { my $useritem = $vars{ $2 }; $actions{$1}{$useritem} }gxe;