$lc_str = $str | ("\x20" x (length $str)); push @index, $-[0] while $lc_str =~ /xxx/g; substr($str, $_, 3) = 'ggg' foreach @index;