use strict; use warnings; use Benchmark qw(:all) ; my $x = $ARGV[0]; my $r = timethese( 5, { a => sub{ open (BOUT, "<", $x) || die "Ther were some problems with opening BLAST output : $!"; $/ = ">#W#"; my $count = 0 ; while(){ $count++ if (m/>/g) ; } $/="\n"; close BOUT; #print "$count \n"; }, b => sub{ open (BOUT, "<", $x) || die "Ther were some problems with opening BLAST output : $!"; my $count = 0 ; while(){ $count++ if (m/>/g); } close BOUT; #print "$count \n"; }, } ); cmpthese $r; Benchmark: timing 5 iterations of a, b... a: 43 wallclock secs (23.06 usr + 1.86 sys = 24.92 CPU) @ 0.20/s (n=5) b: 169 wallclock secs (160.39 usr + 1.34 sys = 161.74 CPU) @ 0.03/s (n=5) s/iter b a b 32.3 -- -85% a 4.98 549% -- #### $/ = ">#W#"; my $count = 0 ; while(){ $count++ if (m/>/g) ; $/="\n"; while(){} $/=">#W#"; } $/="\n";