Hmm... I don't really understand what's going on here.
, pos returns a number. Then, you replace the last succesful match ($&, which is just any character but \n (.)) with a number ($p (= pos (= pos $_))).
Then comes the part of adding the dots. It's a way I'd never thought of, but it's easy to understand.
But I really don't get the part with the one regexp within the other. I just don't get how that pos thingy can actually generate the number the script needs.