/(\+|-)?(\d+)(\+|-)(\+|-)?(\d+)/ =~ gets a = $2.to_i a = -a if $1 == "-" b = $5.to_i b = -b if $4 == "-" if $3 == "+" r = a - b else r = a + b end puts r