my ($here, @places) = 0; while (($here = index $string, $search, $here) != -1) { push @places, $here++; } printf "String %s occured %d times\n\n", $search, scalar @places;