Using Logical Or in Perl regex


#!/usr/bin/perl

use strict;
use warnings;

my %colors=( "life" , "white or black",
 "cat" , "black",
 "horse" , "white or black",
 "blood",    "red",
 "sky" ,"blue");

foreach my $coloredThing (keys %colors)
{
 print "$coloredThing ";
 if ($colors{$coloredThing}=~m/(black|white)/)
 {
 print "Match";
 }
 else
 {
 print "Doesn't Match";
 }
 print "\n";
}

and here the Output

sky Doesn’t Match
blood Doesn’t Match
cat Match
horse Match
life Match

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.