# build the regex, this only needs to be done once my ($genetic_regex) = map qr/$_/, join '|', keys %genetic_code; # apply the regex (my $amino_acid = $seq) =~ s/($genetic_regex)/$genetic_code{$1}/g; return $amino_acid;