>40
perl 5.8.7 + WinXP + Pen4 630でやってみた。

n=100000,N=100で
>the code took: 34 wallclock secs ( 34.53 usr + 0.02 sys)
>the code took: 1 wallclock secs ( 0.89 usr + 0.00 sys)
と大分、差がある。