package C; my $consts = { CONST1 => 1, CONST2 => 2, CONST3 => 3, CONST4 => 4, . . . }; use overload '``' => sub { return $const_values{shift} } ; # All constants can be accessed as by using AUTOLOAD sub AUTOLOAD { no strict 'refs', 'subs'; if ($AUTOLOAD =~ /.*::([A-Z]\w+)$/) { my $const_name = $1; *{$AUTOLOAD} = sub {return $const_values{$const_name}}; return $const_values{$const_name}; } return undef; } 1; #### if($status == C->CONST1) { print "1" } elsif($status =~ /(2|3)/ { print "2 or 3" } else { print 'Something' } #### if($status == C->CONST1) { print "1" } elsif($status =~ /(C->CONST2|C->CONST3)/ { print "2 or 3" } else { print 'Something' } #### $status == C->CONST3 or $status == C->CONST3