use List::Util qw(sum); # in the CPAN $sum = sum map $numeral{$_}, $phrase =~ /([IVXCLMD])/g;