#!/usr/bin/perl -w my @strings = qw( google mississippi that people ); my $alphabet = join "", ( 'a'..'z' ); foreach ( @strings ) { print c( $_, $alphabet ), "\n"; } sub c { my ( $string, $alpha ) = @_; my @letters = split //, $string; my @alphabet = split //, $alpha; my %hash; my @result; my $i = 0; foreach ( @letters ) { if (!defined( $hash{ $_ } )) { $hash{ $_ } = $alphabet[ $i++ ]; } push @result, $hash{ $_ }; } return join "", @result; } # Prints out: #abbacd #abccbccbddb #abca #abcadb