# 3 ways to loop through each character in a string $text = "hello world"; for $i (0..length($text)-1){ $char = substr($text, $i, 1); print "Index: $i, Text: $char \n"; } foreach $char (split //, $text) { print "$char\n"; } foreach $char (split('', $text)) { print "$char\n"; }