my %re = ( boom => [ qw( abc ghi) ], doom => [ qw( mmm nnn) ], zapp => [ qw( xxx yyy) ], ); foreach my $key (keys %hash) { $key =~ /$re{$_}->[0]_(.*)_$re{$_}->[1]/ and $hash{$key} = $_.$1 for keys %re; }