my $max = 0; while ( $digits ) { # iterate through $digits my $next = substr( $digits, 0, $nod ); # get next digits my @fac = split( '', $next ); # get factors my $cur = 1; $cur *= $_ for ( @fac ); # multiply $cur > $max and $max = $cur; # set as maximum if needed substr( $digits, 0, 1, '' ); # delete 1st digit } # while