in reply to Perl treats period as space in string

It's confusing to define the regexp in a variable, then place it there between the /../; The reason is that in the assignment it's very much just a string. When you place it in the regexp context, it suddenly means something different (i.e., the "dot"). So don't do that unless it's very cleary you're dynamically defining your regular expression, otherwise you're just making it more confusing for you and anyone else who may be looking at this even in the very near future.

Replies are listed 'Best First'.
Re^2: Perl treats period as space in string
by BillKSmith (Monsignor) on Jul 21, 2021 at 18:49 UTC
    You can solve this problem with qr in Regexp Quote Like Operators.
    use strict; use warnings; use Test::More tests => 2; my $phrase = qr/club\.market/; unlike( 'club market', $phrase, 'not match space' ); like( 'club.market', $phrase, 'match period' );

    RESULT,

    1..2 ok 1 - not match space ok 2 - match period
    Bill