use URI; my $dir='acm'; ...looping through the file ...$foo contains the URL from the logfile my $u=new URI($foo); if($u->path()=~/^\/$dir\//){ .. do stuff in here 'cause we got an "/acm/" line }