$infile="hosts.txt"; open(INPUT, $infile) || die "Error opening $infile\n"; my @allhosts = ; foreach $approvhost () { foreach $host (<@allhosts>) { if ($host =~ m/^$approvhost/) { print $host; } } }