Функция выглядит следующим образом:

sub formating_money {
	my $num = shift;

	my $rounded = $num;
	if ($num =~ m|\.|) {
		$rounded = sprintf("%.2f", $num);
	}

	while ($rounded =~ s/^(-?\d+)(\d\d\d)/$1\n$2/){};

	return $rounded;
}