use strict; use warnings; my $mystring = "This is a non-sense sentence."; my $query = "non-sense"; print $mystring =~/\b($query)\b/i ? "Matched" : "Missed";