Sounds like you just need eval. I suggest that you turn your rules into subroutines that can be cached.
#!/usr/bin/perl -w use strict; use warnings; # Build list of translation rules my @rules; while (<DATA>) { chomp; my ($pattern, $code) = split "\t"; push @rules, [$pattern, eval "sub {$code}"]; warn $@ if $@; }; # Fake Data my @lines = ( "this is foo\n", "this is bar\n", "this is baz and foo\n", ); # Process the lines using compiled rules. for my $line (@lines) { for my $rule (@rules) { if ($line =~ /$rule->[0]/) { $rule->[1]->($line); } } print "$line"; } __DATA__ foo $_[0] =~ s/foo/FOO/; bar $_[0] =~ s/bar/BAR/; baz $_[0] =~ s/baz/BAZ/;
This way you can use whatever perl translations that you want. Also, it would be up to you what you pass to the subroutines and if it needed to return anything.

In reply to Re: Converting strings read from a file into perl commands by wind
in thread Converting strings read from a file into perl commands by Nightthrall

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.