#! /usr/bin/perl -w use strict; use Benchmark; my $scratch = '/tmp/foo'; # create a really big file open OUT, ">$scratch" or die "$scratch: $!\n"; print OUT join( "\n", 1..1000000 ), "\n"; close OUT; timethese( shift || 20, { '$_' => sub { my $count = 0; open IN, $scratch or die "$scratch input: $!\n"; while( ) { chomp; $count += $_; } close IN; }, 'my' => sub { my $count = 0; open IN, $scratch or die "$scratch input: $!\n"; my $rec; while( defined( $rec = )) { chomp $rec; $count += $rec; } close IN; }, } ); unlink $scratch;