To check if a string ends with a specific suffix in Perl, you can use the regular expression =~
operator.
In this example,
$str1
with a value of "Hello World"
.=~
operator with the regular expression /World$/
.$str1 = "Hello World";
$ends_with_world = $str1 =~ /World$/;
print "String ends with suffix 'World': $ends_with_world\n";
String ends with suffix 'World': 1
In this example,
$str2
with a value of "apple"
.=~
operator with the regular expression /banana$/
.$str2 = "apple";
$ends_with_banana = $str2 =~ /banana$/;
print "String ends with suffix 'banana': $ends_with_banana\n";
String ends with suffix 'banana': 0
In this tutorial, we learned How to Check if String ends with Specific Suffix in Perl language with well detailed examples.