Perhaps the variable doesn't contain exactly what you think it does (eg invisible control characters). Or perhaps it's some wierd object with an overloaded numification operator. Try adding this on the line before to see exactly what it is:
use Devel::Peek;
Dump $step;
my $mid = $lupdate % $step ;