use POSIX qw(log10); my $round_to = 10 ** int(log10 $max) / 5; $max = $round_to * (1 + int($max / $round_to)); $p->set(y_max_value => $max );