in reply to do something if hash keys match regex

Braces? Braces? We don't need no stinkin' braces.

#!/usr/bin/perl # http://perlmonks.org/?node_id=1195568 use strict; use warnings; use Data::Dumper; my %hash = ( xxx_text10_yyy => 1, xxx_text11_yyy => 1, mmm_text12_nnn => 1, mmm_text13_nnn => 1, abc_text6_ghi => 1, abc_text7_ghi => 1, abc_text8_ghi => 1, abc_text9_ghi => 1 ); print Dumper(\%hash); %hash = ( %hash, map( /abc_(.*)_ghi/ ? ( $_, "boom_$1" ) : /mmm_(.*)_nnn/ ? ( $_, "doom_$1" ) : (), keys %hash ) ); print Dumper(\%hash);