use strict; my %p2C; my %C2p; key ('thequickbrownfoxjumpsoverthelazydogs',10); printKeys(\%p2C); printKeys(\%C2p); sub printKeys { my $href = shift; print "\nCT: "; print(($_).' ') foreach (sort keys %{$href}); print "\npt: "; print(($$href{$_}).' ') foreach (sort keys %{$href}); print "\n"; } sub key { my @kp = grep /[a-z]/, split //, shift; my $caesar= shift; my @alpha = ('A'..'Z'); push @alpha, shift @alpha for (1..$caesar); foreach (@kp,'a'..'z') { if (not exists $p2C{$_}) { my $k = shift @alpha; $p2C{$_}=$k; $C2p{$k}=$_; } } }