To iterate over words in a string in Perl, you can use the split
function with a space as the delimiter.
In this example,
$str
with a value of 'Hello World Perl'
.split(' ', $str)
function on the string to split it into words based on spaces.$str = 'Hello World Perl';
@words = split(' ', $str);
foreach $word (@words) {
print $word . "\n";
}
Hello World Perl
In this tutorial, we learned How to Iterate over Words in String in Perl language with well detailed examples.