Total Elapsed Time = 0.719999 Seconds User+System Time = 0.186597 Seconds Exclusive Times %Time ExclSec CumulS #Calls sec/call Csec/c Name 17.1 0.032 0.032 2335 0.0000 0.0000 main::method2 16.6 0.031 0.031 2335 0.0000 0.0000 main::method3 8.57 0.016 0.016 2 0.0080 0.0080 main::BEGIN 0.00 0.000 -0.000 1 0.0000 - strict::import 0.00 0.000 -0.000 1 0.0000 - strict::bits 0.00 0.000 -0.000 1 0.0000 - warnings::BEGIN 0.00 0.000 -0.000 1 0.0000 - Exporter::import 0.00 0.000 -0.000 1 0.0000 - warnings::import 0.00 0.000 -0.000 2335 0.0000 - main::method1 #### #! c:\perl\bin use strict; use warnings; my $text=""; my @abstracts=(); open(FH, "pc clean25.txt") or die ("can't"); $text=join("",); (@abstracts)=($text=~/(.*?)<\/ABSTRACT>/sg); foreach my $abstract (@abstracts) { print "method 1: ",method1($abstract, "prostate"),"method 1: ",method2($abstract, "prostate"),"method 3: ",method3($abstract, "prostate"); } sub method1 { my $text=shift; my $gene=shift; my $count = () = $text =~ /$gene/g; return $count; } sub method2 { my $text=shift; my $gene=shift; my $count=0; my $p=0; ++$count while $p = 1+index( $text, $gene, $p ); return $count; } sub method3 { my $text=shift; my $gene=shift; my $count=0; my $patn = qr/\b$gene\b/; $count++ while $text =~ /$patn/g; return $count }