sub foo { my $format_string = shift; my %vars = ( a => ..., b => ..., c => ..., ); $format_string =~ s/(%(\w))/$vars{$1}/eg; return $format_string; }