Here's a snippet that I think does what you mean?
# assuming that...
my $string = "Perl Monks";
my $n = length($string);
my $i = 1;
my $result = 0;
# here it is.
$result += ord($_) * 31^($n-$i++) for split '', $string;
^ ^ ^ ^ ^ ^ ^ ^
| | | | | | | +-- String to split
| | | | | | +-- split all the charact
| | | | | +-- post increment $i
| | | | +-- $i is the index
| | | +--- $n is the length of $string
| | +--- this is the character returned from split
| +--- ord() returns the ascii code of the character
+--- add what we have to $result
He who asks will be a fool for five minutes, but he who doesn't ask will remain a fool for life.
Chady | http://chady.net/