Okey, just another simple problem to check how well you know Perl! contexts[perldata#Context]. Definitely this link is a good key to the problem below. But before checking documentation, consider the following code :

my $string = "3242 4 3 3 111"; # just for test purposes 
print $string =~ /\d+/g;
print (() = $string =~ /\d+/g);
print ($count = () = $string =~ /\d+/g);

What can you expect it does? It does the following :

First line prints all array elements, Second line prints nothing Last line prints number of elements in matched array.

  If you known this - great, but explanation for everyone who are not familiar with contexts may look quite straightforward, but I’ll say that there is nothing unexpected.

Second line print nothing as whole print expression expects LIST context variable, but in this context the list assignment result is the left side of assignment which is (), so it prints nothing.

The last line prints scalar variable $count, value of which is derived from list assignment. But in scalar context list assignment result is the right side. What is the right side? Matches in scalar context which is exactly the number of elements int array.

So, that’s it!

Just to clarify top results, here is another snippet :

[root@vagrant-centos65 ~]# perl -e 'print (() = (1..10))';
[root@vagrant-centos65 ~]# perl -e 'print (@arr = ($a, $b) = (1..10))';
[root@vagrant-centos65 ~]# perl -e 'print ($sz = ($a, $b) = (1..10))';