my $found; my $counter; for (@line) { $counter++; if ($_ =~ /$search/i) { print "\nLine that matched <$search> found on line $counter\n"; print "$_\n"; $found++; } } if ( $found ) { print "$count found words total\n"; } else { print "\nsubstring <$search> NOT found\n"; }