use List::Util qw[ reduce ]; sub xform{ my $word = shift; $word =~ tr[ACGT][\x00\x01\x02\x03]; reduce{ ($a << 2) + $b } 0, unpack 'C*', $word; }