my $val = 0; $val = $val * 10 + substr( $cur, -1, 1, undef ) while $cur;