use strict; use warnings; my @b = ( "corp.home.ge.com", "scotland.gcf.home.ge.com", "marketing.ge.com", "home-school.com" ); my %b; $b{$_} = 0 for @b; for () { $_ = lc $_; m/^https?:\/\/(?:www.)?(.*?)[\/\n]/; $b{$1}++ if exists $b{$1}; } print "$_ => $b{$_}\n" for @b; __DATA__ http://corp.home.ge.com/page/whatever.php3 https://scotland.gcf.home.ge.com http://sub.marketing.ge.com/ HTTP://marketing.ge.com/ http://www.home-school.com/mypage.html http://home-school.com/mypage.html https://MARKETING.ge.com/testpage.html