use bigint; my $f=3; for (1..12) { $f = ($f-1)**2 if $_>1; say $f } # Faster: replace bigint with Math::GMP qw/:constant/;