# Note: use v5.12+ implies use strict (and enables feature state) # use v5.36+ implies use strict and warnings (and enables feature state) use v5.38; use List::Util qw(reduce); sub roman_to_dec { state %rtoa = ( M=>1000, D=>500, C=>100, L=>50, X=>10, V=>5, I=>1 ); reduce { $a+$b-$a%$b*2 } map { $rtoa{$_} } split//, uc(shift); } my @testdata = ( "XLII", "LXIX", "mi" ); for my $r (@testdata) { print "$r: ", roman_to_dec($r), "\n"; }