use Math::BigInt; @Primes = (2,3,5,7,11,13,17,19,23,29,31,37,41, 43,47,53,59,61,67,71,73,79,83,89,97,101); @AsciiPrimes = ((0) x 65, @Primes, (0) x 6, @Primes, (0) x 133); print StringDif('abcdgoldfish', 'flash'),"\n"; print StringDif('lmnogoldfish', 'dish'),"\n"; print StringDif('osar', 'oar'),"\n"; sub StringDif { my ($StrA, $StrB) = @_; my $A = Math::BigInt->new(1); my $B = Math::BigInt->new(1); my $Quot, $Rem, $NewQuot, $ReturnStr; foreach (unpack 'C*', $StrA) {$A *= $AsciiPrimes[$_]} foreach (unpack 'C*', $StrB) {$B *= $AsciiPrimes[$_]} if ($A eq '+0' or $B eq '+0') { warn "Non-letter in string"; return undef } ($Quot, $Rem) = Math::BigInt->new($A)->bdiv($B); return undef unless $Rem eq '+0'; $ReturnStr = ''; foreach('a'..'z') { do { ($NewQuot, $Rem) = Math::BigInt->new($Quot) ->bdiv($AsciiPrimes[ord $_]); if ($Rem eq '+0') { $ReturnStr .= $_; $Quot = $NewQuot } } while $Rem eq '+0' } return $ReturnStr }