CODE: #!/usr/bin/perl -w use strict; # $n is number to round, $d is "divisor" for rounding units sub roundup { my ($n, $d) = @_; return ( int( $n / $d ) + ( ( $n % $d ) ? 1 : 0 ) ) * $d; } for my $i ( 0,4,5,6,9,10,11,24,25,26) { print "$i -> " . roundup($i,5) . "\n"; } for my $i ( 99,100,101,124,125,126,149,150,151) { print "$i -> " . roundup($i,25) . "\n"; } for my $i ( 999, 1000, 1001, 1249, 1250, 1251, 1499,1500,1501) { print "$i -> " . roundup($i,250) . "\n"; } RESULT: 0 -> 0 4 -> 5 5 -> 5 6 -> 10 9 -> 10 10 -> 10 11 -> 15 24 -> 25 25 -> 25 26 -> 30 99 -> 100 100 -> 100 101 -> 125 124 -> 125 125 -> 125 126 -> 150 149 -> 150 150 -> 150 151 -> 175 999 -> 1000 1000 -> 1000 1001 -> 1250 1249 -> 1250 1250 -> 1250 1251 -> 1500 1499 -> 1500 1500 -> 1500 1501 -> 1750