use Benchmark 'cmpthese'; my @a = map {"$_\n"} 1..1000000; cmpthese(100, { forloop => sub { open FILE, ">file.out" or die "Can't open file: $!\n"; print FILE $_ for @a; close FILE; }, array => sub { open FILE, ">file.out" or die "Can't open file: $!\n"; print FILE @a; close FILE; } }); #### Benchmark: timing 100 iterations of array, forloop... array: 28 wallclock secs (22.62 usr + 2.74 sys = 25.36 CPU) @ 3.94/s (n=100) forloop: 69 wallclock secs (61.52 usr + 2.75 sys = 64.27 CPU) @ 1.56/s (n=100) Rate forloop array forloop 1.56/s -- -61% array 3.94/s 153% --