#!/usr/bin/perl # illustrates simple pattern mattching # () group pattern elements. # * : preceding character, element, or group of elements may occur 0,1,..times # + the preceding element or group of elements must occur at least once. # ? matches zero or one times. $s = 'One if by land and two if by sea'; $x = "lamp"; print $s "\n"; if ($s =~ /if by la/) {print "YES \n"} else {print "NO \n"} if ($s =~ /one/) {print "YES \n"} else {print "NO \n"} if ($s =~ /one/i) {print "YES \n"} else {print "NO \n"} if ($x =~ /l.mp/) {print "YES \n"} else {print "NO \n"} if ($x =~ /l?mp/) {print "YES \n"} else {print "NO \n"}