sub spread { return ($_[0] % $_[1])?join("-", ((int($_[0] / ($_[1] - 1))) x ($_[1]-1), ($_[0] % ($_[1] - 1)))):join("-", (int($_[0] / $_[1])) x $_[1]); } print spread(19,4); #test first branch of ?: print spread(25,5); #test second branch of ?: