in reply to How do I add commas to a number?

From perlfaq5:
This regexp will add commas to numbers:
s/(^[-+]?\d+?(?=(?>(?:\d{3})+)(?!\d))|\G\d{3}(?=\d))/$1,/g;

Originally posted as a Categorized Answer.