open(INPUT, "hosts.txt") || die "Error opening 'hosts.txt'\n"; my @hosts = ; while () { chomp($_); foreach $host (@hosts) { if ($host =~ m/^$_/) { print "Host found: '$host'\n"; } } }