use strict; my $str = "aabceezazerrfde"; my %values = ('a' => 7, 'e' => 2, 'z' => 26); my $total = 0; foreach(split '',$str){ if($values{$_}){ $total += $values{$_}; } } print "Total: $total";