use URI; my $addr = URI->new($url); my $path = $addr->path; for my $ext (@image_extensions) { if ($path =~ /\.$ext$/) { ....