use strict; use warnings; use diagnostics; my @char; my $art; my $string = 'abcdefghijk'; my %match = (bc => "Michelangelo", efg => "Raffaello",de => "Caravaggio",ijk => "Tintoretto",hij=>"Leonardo",); @char = split //,$string; #check that the substring is in hash; foreach $art (keys %match){ if ($string=~/$art/){ print "There's a match in the string to $art =>", $match{$art}++,"\n"; } } #now using GREP foreach $art (keys %match){ if (my $seen= grep {$string =~ $art}$match{$art}) { print "I have seen using GREP $art=>",$match{$art},"\n"; } } #using ~~ match operator foreach $art (keys %match){ print "this is \~~ $art=> ",join('',$match{$art}) if /$string/i ~~$art; } #using INDEX() foreach $art (keys %match){ print "this is INDEX $art =>",join('',$match{$art}),"\n", if index my $tring,$art; }