use Lingua::EN::Inflect qw(NUMWORDS); sub get_columns { my ($max_cols, $amount, $number) = @_; if ($amount <= $max_cols ** 2) { for my $num (1..$max_cols) { if ($amount >= $num ** 2 && $amount < ($num + 1) ** 2) { return $number && $number =~ /^[yt1]/ ? $num : NUMWORDS($num); } } } else { return $number && $number =~ /^[yt1]/ ? $max_cols : NUMWORDS($max_cols); } }