sub f { %h=(I=>1,V=>5,X=>10,L=>50,C=>100,D=>500,M=>1000); $f=0; my$r; $c=$h{$_}, $c < $f ? $r-=$c : {$f=$c, $r+=$c} for reverse split //,shift; $r }