$ cat 938978.pl #!/usr/bin/perl use strict; use warnings; while () { chomp; my ($x, $y) = split /\s+/,$_; last if ! defined $y; print robo_1($x,$y), " <$x> <$y>\n"; } sub robo_1 { my %h; $h{$_}++ for split//,shift; $h{$_}-- for split//,shift; my $t=0; $t += ($_>0 ? $_ : -$_) for values %h; return $t; } __DATA__ 123456 abcdefghijkl ARF_ARF_ARF BARKBARKBARK doom gloom heartbreak anguish $ perl 938978.pl 18 <123456> 11 3 13