Your problem is that each match eats two "~" characters. So it'll skip every other section.

Try this instead:

$document =~ m!~\s*([^~]+?)\s*(?=~|$)!g;

In reply to Re: You need more coffee when... by bart
in thread You need more coffee when... by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":