绑定操作符=~ :告诉perl,拿右边的模式来匹配左边的字符串,而不是匹配$_
my $likes_perl = <STDIN> =~/\byes\b/i;
捕获变量
$1,$2,$3 #匹配第1个、2个、3个,括号的内容
$_ = "hello there,neighbor";
if (/(\S+) (\S+) ,(\S+) /) {
print "words were $1 $2 $3\n";
}
运行结果:words where hello there neighbor
捕获变量的存续期:存活到下次匹配成功为止
my $wilma = '123';
$wilma =~ /([0-9]+)/;
$wilma =~ /([a-z]+)/;
print ("wilma's word was $1 \n") #$1的内容仍旧是123
不捕获模式:(?:)