Mega Code Archive

 
Categories / Perl / Regular Expression
 

Using alternate with parentheses

#!usr/bin/perl use strict; use warnings; my $string1 = "hello"; my $string2 = "hello there"; my $string3 = "hi there"; print "$string1\n$string2\n$string3\n"; print "1: how are you?\n" if ( $string1 =~ m/(hello|hi) there/ ); print "2: how are you?\n" if ( $string2 =~ m/(hello|hi) there/ ); print "3: how are you?\n" if ( $string3 =~ m/(hello|hi) there/ );