in reply to numbers with chainable comparisons

Here's another approach to changing how expressions are parsed: start with strings and eval them after you've turned them into the Perl equivalent. The dechain sub turns a string into a series of and-ed expressions, which you could then eval.
my $op = qr/[!=<>]+/; sub dechain { my @terms; while ($_[0] =~ /(.+?)($op)(?=((?:(?!$op).)+))/g) { push @terms, join '', $1, $2, $3; } join ' and ', @terms; } print dechain('3 < 4 < 5'), "\n"; print dechain('$x < $y <= $z'), "\n";

Caution: Contents may have been coded under pressure.