my $ind = -1; while (($ind = index($string, $substring, $ind+1) >= 0) { push @offsets, $ind }