As using the string form of eval with untrusted input is a considerable security risk, and your markdown can easily contain double-quotes which break your code, maybe you are interested in using a templating system or simply applying this very small, very simple templating system? It allows you to restrict what variables get interpolated, and it prevents execution of arbitrary code:

sub interpolate { my ($text, %vars) = @_; $text =~ s!\$(\w+)|\$\{(\w+)\}! my $name = $1 || $2; exists $vars{ $name } ? $vars{ $name } : '$' . $name !ge; return $text }; print interpolate( 'Hello $user, this is $var1. We also use the unknown variable $foo +.', var1 => 'The value of var1', user => 'Je55eah', # ... );

In reply to Re^2: my $scope as the default for variables by Corion
in thread Please help me print this hash. by Je55eah

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.