package Regexp; use overload q{cmp} => sub { return 1 if (ref($_[0]) ne ref($_[1])); # TODO: returning 1 is completely arbitrary # didn't know how to decide which ref is "bigger" return "$_[0]" cmp "$_[1]"; }, fallback => 1; ; package main; my $rx = qr/a/; my $ry =qr/a/; my $x="(?-xism:a)"; use Test::More 'tests' => 2; cmp_ok( $rx, 'eq', $ry, '$rx eq $ry'); cmp_ok( $rx, 'ne', $x, '$rx ne $x');