#!/usr/bin/perl use strict; my ($guess,$num); # get number while() { $guess = $num = $_+0; last if ($num>0); } # iterate until within 1e-13 # go further and you need some math module, I think :) while (abs($num - $guess**2) > 1e-13) { $guess = (($num/$guess) + $guess)/2; } # print our guess and what Perl says print "My guess of square root of $num is $guess\n"; print "Perl says it's ".$num**.5."\n"; #### #!/usr/bin/perl use strict; my $n; while() { $n = $_+0; last if $n>0} while (abs($n - $_**2) > 1e-13){ $_ = ($n/$_ + $_)/2} print "Guess: $_\nperl: ".$n**.5."\n";