my $start_run = time(); use strict; use Benchmark; use warnings; my @array = (1..1000000000); foreach (@array) { if ($_==reverse(substr($_, 0, 1) * substr($_, 1))) { print $_."\n" ;} if ($_==reverse(substr($_, 0, 2) * substr($_, 2))) { print $_."\n" ;} if ($_==reverse(substr($_, 0, 3) * substr($_, 3))) { print $_."\n" ;} if ($_==reverse(substr($_, 0, 4) * substr($_, 4))) { print $_."\n" ;} if ($_==reverse(substr($_, 0, 5) * substr($_, 5))) { print $_."\n" ;} if ($_==reverse(substr($_, 0, 6) * substr($_, 6))) { print $_."\n" ;} if ($_==reverse(substr($_, 0, 7) * substr($_, 7))) { print $_."\n" ;} } my $end_run = time(); my $run_time = $end_run - $start_run; print "Time taken: ".$run_time." sec\n"; #### use strict; use warnings; use Time::HiRes qw( time ); my $start_run = time(); for my $n (100..1_00_000_000) { my $r = reverse($n); my $x = 100; while ($x <= $n) { if (int($n / $x) * ($n % $x) == $r) { print "$n\n"; last; } $x *= 10; } } my $end_run = time(); my $run_time = $end_run - $start_run; print "Time taken: ".$run_time." sec\n";