sub x { %m = qw/V 4 L 49 X 9 C 99 D 499 M 999/; for (split //, $l = $t = shift) { $t += ($n = 1 + $m{$_}) - 2 * ($n > $l) * $l; $l = $n } $t }