package Foo::Bar; ... use constant RX => qr{ hello }xms; ... sub new { ... } ... sub method { my $self = shift; ... if ($self->{bar} =~ RX) { ... } ... } ... 1;