Perl 6 An Introduction to Perl 6 #24

Smart matching

Perl 5's =~ operator becomes ~~ ("smart match") in Perl 6

$x ~~ /^ 'msg' \d+ '.txt' $/   # normal regex match

But it can also be used with other types

$spot ~~ Dog                   # $spot isa Dog

@a ~~ @b                       # array equality

@a ~~ / foo /                  # elements of @a matching 'foo'

$y ~~ $n..$m                   # range match $n <= $y <= $m
Copyright © 2008 Patrick Michaud