... my $match = 0; for (@line) { ... if ($_ =~ /$search/i) { print ...; $match++; } } if (!match) { print "not found"; }