If you regular expressions as your keys, then you save the overhead of recompiling them everytime. The qr// operator does this for you.
my %Ren2Dol = ( qr(rrv193\d{4}cm) => "RNF191", qr(rrv194\d{4}cm) => "RNF196", qr(rrv195\d{4}cm) => "RNF200", );

Here's your code with tests. This does the actual search/replace as necessary as it converts @data to @output.

use strict; use warnings; use Test::More tests=>1; use Data::Dumper; my %Ren2Dol = ( qr(rrv193\d{4}cm) => "RNF191", qr(rrv194\d{4}cm) => "RNF196", qr(rrv195\d{4}cm) => "RNF200", ); my @data = qw( rrv1931009cm.new090626 rrv1941009cm.new090626 rrv1951009cm.new090626 rrv1961009cm.new090626 rrv1931234cm.new090626 ); my @expected = qw( RNF191.new090626 RNF196.new090626 RNF200.new090626 rrv1961009cm.new090626 RNF191.new090626 ); my @output; foreach (@data) { while( my( $regex, $replace ) = each (%Ren2Dol)) { s/$regex/$replace/ex; } push @output, $_; } is_deeply( \@expected, \@output, "names updated correctly") or diag( Dumper{ expected=>\@expected, got=>\@output });

In reply to Re^2: regular expression in a hash by spazm
in thread regular expression in a hash by lamasculo

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.