in reply to matching a line from one file in another

I didn't test this, but I think what you want is:
$infile="hosts.txt"; open(INPUT, $infile) || die "Error opening $infile\n"; my @allhosts = <INPUT>; close INPUT; while ($approvhost=<STDIN>) { chop($approvedhost); # or it won't partially match # your hosts entries becaus of # the training \n unless ($approvedhost) { last; } # so you can quit # with a null entry foreach $host (@allhosts) # omit the <> you're not # reading a file or stdin { if ($host =~ m/^$approvhost/) { print $host; } } }