in reply to Formatting a number
This is a FAQ. Please type perldoc -q commify and/or read the documentation online.
$num =~ s/(^[-+]?\d+?(?=(?>(?:\d{3})+)(?!\d))|\G\d{3}(?=\d))/$1,/g; [download]