Perhaps I'm misunderstanding your issue's description, but it sounds like the following: given a set of characters and a hash key, return (chars in key / 5) * $hash{key}. If this is the case, perhaps the following will work for you:
use Modern::Perl;
my %hash = (
ABCDE => 12,
FGHIJ => 7,
KLMNO => 2
);
say getMatchResult( 'AC', 'ABCDE' );
sub getMatchResult {
my ( $find, $key ) = @_;
my $matches = () = $key =~ /[$find]/ig;
( $matches / 5 ) * $hash{$key};
}
Output:
4.8
Hope this helps!
Update: Thanks to hmb for suggesting the goatse operator (and character class). It timed faster than my iterative solution w/regex. |