programming-examples/perl/Regular_Expression/parentheses.pl
2019-11-15 12:59:38 +01:00

45 lines
895 B
Perl

#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/ );
#Using alternate without 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 "watch this:\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/ );