in reply to matching a line from one file in another

You forgot to remove the \n character when they submitting the value to STDIN. Try this,

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

As someone pointed out, the foreach should not be used with the STDIN and the brackets around @allhosts was wrong too. Fixed.

Replies are listed 'Best First'.
Re^2: matching a line from one file in another
by New_to_this_stuff (Initiate) on Apr 14, 2006 at 17:00 UTC
    Thank you for your speedy reply, it is now doing what I need it to!