use File::Basename; #list of filenames to normalize my @index_file_names=qw(index.html index.htm index.php index.asp index.cgi); normalize_url('foo'); normalize_url('bar/index.php'); sub normalize_url { my $old_url = $_[0]; chomp($old_url); #saves name at the end my $filename=basename($old_url); if (grep {$_ eq $filename} @index_file_names) { #saves the directory part my $normalized_url=dirname($old_url); #$normalized_url; print "$old_url: found\n"; }else{ #don't need to normalize url #$old_url; print "$old_url: not found\n"; } } __END__ foo: not found bar/index.php: found