http://qs321.pair.com?node_id=212803

This snippet converts a Roman numeral (<= 4000) to its value. It will also reject poorly-formed Roman numerals. Obviously this is a learning exersize, as I'm new to Perl. Any suggestions for improvements would be very welcome.
print "Enter a Roman numeral: "; chomp ($_ = <STDIN>); unless (m/^ m{0,3} # thousands (cm|dc{0,3}|cd|c{0,3}) # hundreds (xc|lx{0,3}|xl|x{0,3}) # tens (ix|vi{0,3}|iv|i{0,3}) # ones $/ix) { die "That doesn't appear to be a well-formed Roman numeral.\n"; } $val = 0; if (s/cm//i) {$val += 900;} if (s/cd//i) {$val += 400;} if (s/xc//i) {$val += 90;} if (s/xl//i) {$val += 40;} if (s/ix//i) {$val += 9;} if (s/iv//i) {$val += 4;} while (m/m/g) {$val += 1000;} while (m/d/g) {$val += 500;} while (m/c/g) {$val += 100;} while (m/l/g) {$val += 50;} while (m/x/g) {$val += 10;} while (m/v/g) {$val += 5;} while (m/i/g) {$val += 1;} print "$val\n";