my %data = ( Y => $year, m => $month, d => $day, ... ); $format =~ s/\%([A-Za-z])/ exists $data{$1} ? $data{$1} : "%$1" /ge;