#!/usr/bin/env perl -l use strict; use warnings; my @dna_seqs = qw{ATGCCCGTAC GCTTCCCAGCGC}; print "$_ => ", dna_prot_map($_) for @dna_seqs; { my %code; BEGIN { %code = qw{ATG M CCC P GTA V GCT A TCC S CAG Q CGC R} } sub dna_prot_map { join '', map $code{substr $_[0], $_*3, 3}, 0..length($_[0])/3-1 } } #### ATGCCCGTAC => MPV GCTTCCCAGCGC => ASQR #### sub f { state $static_var = ... ... do something with $static_var here ... } #### { my $static_var; BEGIN { $static_var = ... } sub f { ... do something with $static_var here ... } } #### { my $static_var; BEGIN { $static_var = ... } sub f { ... do something with $static_var here ... } sub g { ... do something with $static_var here ... } }