#!/usr/bin/perl use strict; use warnings; sub calc { my $string = shift; my %p = ( A => 1.5, B => 2.5, C => 3.5, ); # in another thread, he indicated this was the series he needed my @divisors = ( 50/100, 55/100, 60/100, 65/100, 70/100, 75/100, 80/100, 85/100, 90/100 ); my $result = 1; # in another thread, he said he needed to match A,B,C,D,E,F,G,H and J my @substrings = $string =~ /(\d{0,1}[A-HJ])/g; for( @substrings ){ my $divisor = shift @divisors; my( $exponent, $letter ) = /(\d){0,1}([A-HJ])/; $exponent ||= 1; $result *= $p{ $letter } ** $exponent * $divisor; } return $result; } for( qw( 2A 2B 2A2B2C 4ABC 4AC ABC BC ) ){ print "string: $_\n"; my $result = calc( $_ ); print "result: $result\n\n"; }