... my( $p, $i ) = 0; $p += $i while $i = 1+index $haystack, $needle, $i; ... #### ... my( $p, $i ) = 0; do{ $p += $i; print "$p : $i, other stuff"; } while $i = 1+index $haystack, $needle, $i; ... #### my( $p, $i ) = 0; loop { $p += $i; last if $i = 1+index $haystack, $needle, $p; }