my @tokens = split '', $ARGV[0]; my %meta = ( 't' => \&time, 'l' => \&log_level, 'm' => \&message, ); my $max_iter = scalar @tokens; TOKEN: while ($indx < $max_iter) { if ($tokens[$indx] eq '%') { $indx++; for my $key (keys %meta) { if ($tokens[$indx] eq $key) { $output = $output . &{ $meta{$key} }; next TOKEN; } } $output = $output . '%' . $tokens[$indx]; next TOKEN; } $output = $output . $tokens[$indx]; } continue { $indx++; } print "\n$output\n"; #### $format =~ s/(%m)/&message()/;