Q:

How does =~ behave in matching?

I am confused in the =~ operator. It seems that it returns a value that is true/false of a match. But when applied using a g it returns the actual matches.
Example:  
 ~
$ perl -e '  
my $var = "03824531449411615213441829503544272752010217443235";  
my @zips = $var =~ /\d{5}/g;  
print join "--", @zips;  
'
03824--53144--94116--15213--44182--95035--44272--75201--02174--43235  

$ perl -e '  
my $var = "03824531449411615213441829503544272752010217443235";  
my @zips = $var =~ /\d{5}/;  
print join "--", @zips;  
'  
1  

$ perl -e '  
my $var = "03824531449411615213441829503544272752010217443235";  
my $zips = $var =~ /\d{5}/;  
print join "--", $zips;  
'  
1  

So how does this work? Why does it return true/false in non-g mode?Or is it something else?

A:

perlop already given a pretty clear explanation for this, so I will just copy & paste related part of it:
For =~ operator:

Binary "=~" binds a scalar expression to a pattern match. ... When used in scalar context, the return value generally indicates the success of the operation. ... Behavior in list context depends on the particular operator. See Regexp Quote-Like Operators for details and perlretut for examples using these operators.

For m// operator:

Searches a string for a pattern match, and in scalar context returns true if it succeeds, false if it fails.

For m// without /g modifier in list context:

If the /g option is not used, m// in list context returns a list consisting of the subexpressions matched by the parentheses in the pattern, that is, ($1, $2, $3 ...). When there are no parentheses in the pattern, the return value is the list (1) for success. With or without parentheses, an empty list is returned upon failure.

For m// with /g modifier in list context:

The /g modifier specifies global pattern matching--that is, matching as many times as possible within the string. How it behaves depends on the context. In list context, it returns a list of the substrings matched by any capturing parentheses in the regular expression. If there are no parentheses, it returns a list of all the matched strings, as if there were parentheses around the whole pattern.
In scalar context, each execution of m//g finds the next match, returning true if it matches, and false if there is no further match.

Context of expressions in OP:

@zips = $var =~ /\d{5}/g;
m//g in list context;

@zips = $var =~ /\d{5}/;
m// in list context;

$zips = $var =~ /\d{5}/;
m// in scalar context.

A:

$var =~ /(\d{5})/; also returns match in list context, it's only that /g does grouping regardless of () braces.

