my $dir='/acm/'; my $strlen=length ($dir) while () { my $url = (split())[6]; if ((substr($url,0,$strlen) eq $dir) && ($url=~/$error/)) { if (exists $report{$url}) { $report{$url}++; } else { $report{$url} = 1; } } }