01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | #!/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