sub foo { my $format_string = shift; my $a = ...; my $b = ...; ... my $z = ...; $format_string =~ s/(%(\w))/eval "$$2"/e; return $format_string; }