http://www.perlmonks.org?node_id=11119325

tel2 has asked for the wisdom of the Perl Monks concerning the following question:

Beloved Monks,

I seek your wisdom re why the 4th one-liner below returns "Matches!".  The other 7 one-liners behave as I would have expected.  I thought $a.$b would be the same as "$a$b" in contexts like this - it seems to be with last 'eq' tests.  Was I mistaken?  If I print them the output looks the same.

$ perl -e '$a="A";$b="B";print "Matches!\n" if "$a$b" =~ /A/' Matches! $ perl -e '$a="A";$b="B";print "Matches!\n" if "$a$b" =~ /C/' $ perl -e '$a="A";$b="B";print "Matches!\n" if $a.$b =~ /A/' Matches! $ perl -e '$a="A";$b="B";print "Matches!\n" if $a.$b =~ /C/' Matches! # WHY??? $ perl -e '$a="A";$b="B";print "Matches!\n" if "$a$b" eq "AB"' Matches! $ perl -e '$a="A";$b="B";print "Matches!\n" if "$a$b" eq "C"' $ perl -e '$a="A";$b="B";print "Matches!\n" if $a.$b eq "AB"' Matches! $ perl -e '$a="A";$b="B";print "Matches!\n" if $a.$b eq "C"'
I added blank lines above purely for readability.
I'm running Perl 5.16.3 on Linux.
Thanks.
tel2