my $seed = "$name$email$item"; while ($seed =~/(.)/g) { $n += 1; if (uc($1) eq uc('a')) { $i = ($i + 173); } # many many lines and calulations here } my $m=sprintf("%.f",$i) ; my $trimmedNumber = substr($m, -16, 16); # trim 16 from the right. printf ("Trimmed: $trimmedNumber\n");