use strict; use warnings; my $SQUARE; my $MIN_NUMBER = 4; my $MAX_NUMBER = 1000; my $string = q(59738219024971503664); my $total_length; my %seen; for my $start (0..length $string) { next if substr($string, $start, 1) eq '0'; for my $length (1..(length($string)-$start)) { my $test = substr($string, $start, $length); my $sqrt = sqrt($test); if (!$seen{$test}++ and $sqrt == int $sqrt and $sqrt >= $MIN_NUMBER and $sqrt <= $MAX_NUMBER) { $total_length += $length; print "$test\t$length\t$total_length\n"; } } }