use strict; use warnings; my @lines = ; @lines = map {chomp $_; $_} @lines; my $indtwn = ; # $indtwn = until defined $indtwn; ??? chomp $indtwn; my $found = 0; foreach my $townverify (@lines) { my @field = split(':',$townverify); next if $field[0] =~ m/^#/; if ( $field[2] eq $indtwn ){ # <--- here print "FOUND $indtwn\n"; $found++; last; } } print "[$indtwn] NOT FOUND" unless $found; __DATA__ 1:PGH:Pittsburgh 2:PGHW:Pittsburgh West End