+=head3 Switching in a loop
+
+Instead of using C<given()>, you can use a C<foreach()> loop.
+For example, here's one way to count how many times a particular
+string occurs in an array:
+
+ my $count = 0;
+ for (@array) {
+ when ("foo") { ++$count }
+ }
+ print "\@array contains $count copies of 'foo'\n";
+
+On exit from the C<when> block, there is an implicit C<next>.
+You can override that with an explicit C<last> if you're only
+interested in the first match.
+
+This doesn't work if you explicitly specify a loop variable,
+as in C<for $item (@array)>. You have to use the default
+variable C<$_>. (You can use C<for my $_ (@array)>.)
+
+=head3 Smart matching in detail
+
+The behaviour of a smart match depends on what type of thing
+its arguments are. It is always commutative, i.e. C<$a ~~ $b>
+behaves the same as C<$b ~~ $a>. The behaviour is determined
+by the following table: the first row that applies, in either
+order, determines the match behaviour.
+
+
+ $a $b Type of Match Implied Matching Code
+ ====== ===== ===================== =============
+ (overloading trumps everything)
+
+ Code[+] Code[+] referential equality $a == $b
+ Any Code[+] scalar sub truth $b->($a)
+
+ Hash Hash hash keys identical [sort keys %$a]~~[sort keys %$b]
+ Hash Array hash value slice truth grep $_, @$a{@$b}
+ Hash Regex hash key grep grep /$b/, keys %$a
+ Hash Any hash entry existence exists $a->{$b}
+
+ Array Array arrays are identical[*]
+ Array Regex array grep grep /$b/, @$a
+ Array Num array contains number grep $_ == $b, @$a
+ Array Any array contains string grep $_ eq $b, @$a
+
+ Any undef undefined !defined $a
+ Any Regex pattern match $a =~ /$b/
+ Code() Code() results are equal $a->() eq $b->()
+ Any Code() simple closure truth $b->() # ignoring $a
+ Num numish[!] numeric equality $a == $b
+ Any Str string equality $a eq $b
+ Any Num numeric equality $a == $b
+
+ Any Any string equality $a eq $b
+
+
+ + - this must be a code reference whose prototype (if present) is not ""
+ (subs with a "" prototype are dealt with by the 'Code()' entry lower down)
+ * - that is, each element matches the element of same index in the other
+ array. If a circular reference is found, we fall back to referential
+ equality.
+ ! - either a real number, or a string that looks like a number
+
+The "matching code" doesn't represent the I<real> matching code,
+of course: it's just there to explain the intended meaning. Unlike
+C<grep>, the smart match operator will short-circuit whenever it can.
+
+=head3 Custom matching via overloading
+
+You can change the way that an object is matched by overloading
+the C<~~> operator. This trumps the usual smart match semantics.
+See L<overload>.
+
+=head3 Differences from Perl 6
+
+The Perl 5 smart match and C<given>/C<when> constructs are not
+absolutely identical to their Perl 6 analogues. The most visible
+difference is that, in Perl 5, parentheses are required around
+the argument to C<given()> and C<when()>. Parentheses in Perl 6
+are always optional in a control construct such as C<if()>,
+C<while()>, or C<when()>; they can't be made optional in Perl
+5 without a great deal of potential confusion, because Perl 5
+would parse the expression
+
+ given $foo {
+ ...
+ }
+
+as though the argument to C<given> were an element of the hash
+C<%foo>, interpreting the braces as hash-element syntax.
+
+The table of smart matches is not identical to that proposed by the
+Perl 6 specification, mainly due to the differences between Perl 6's
+and Perl 5's data models.
+
+In Perl 6, C<when()> will always do an implicit smart match
+with its argument, whilst it is convenient in Perl 5 to
+suppress this implicit smart match in certain situations,
+as documented above. (The difference is largely because Perl 5
+does not, even internally, have a boolean type.)