in reply to Re: regular expression in a hash
in thread regular expression in a hash

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 });