To check if a string contains a specific character in Perl, you can use the 'index' function.
In this example,
sub contains_character {
my ($str, $ch) = @_;
my $pos = index($str, $ch);
return $pos >= 0;
}
my $str = "Hello World";
my $ch = 'W';
my $contains = contains_character($str, $ch);
print "String contains character '$ch': $contains\n";
String contains character 'W': 1
In this tutorial, we learned How to Check if String contains specific Character in Perl language with well detailed examples.