use strict; use warnings; use File::Find; use Data::Dumper; my %addresses; sub test1 { my ($from); find(sub { return unless -f $_; open my $fh, '<', $_ or die; local $/ = ''; # "Paragraph" mode, reads a block of text to next \n\n $_ = <$fh>; # Read Header block ($from)= $_ =~ /^From:(.*)/m; # /m to anchor #print "$from\n"; close $fh; }, glob('./009_mailtest/*')); #print Dumper \%addresses; } sub test2{ binmode(STDOUT,":utf8"); my ($from,$bgn,$end,$len); find(sub { return unless -f $_; open my $fh, '<:utf8', $_ or die; local $/ = ''; # "Paragraph" mode, reads a block of text to next \n\n $_ = <$fh>; # Read Header block $bgn=index($_,"From:",0) + length("From:"); $end=index($_,chr(10),$bgn+1); $len=$end - $bgn; $from=substr($_, $bgn, $len); #print "$from\n"; close $fh; }, glob('./009_mailtest/*')); } my($start,$end); $start=(times)[0]; &test1; $end=(times)[0]; print "with regex=" . ($end - $start) . "sec\n"; $start=(times)[0]; &test2; $end=(times)[0]; print "without regex=" . ($end - $start) . "sec\n";