#!/usr/bin/perl -w use strict; my @lines = ( 'this is line one', 'this is line TWO', 'this is line three', 'this is line four perl', 'this is line fiveperl', 'perl' ); my @search = grep { index($_,'perl')+1 } @lines; # my @search = grep {/perl/} @lines; # # if you don't want line five use /\bperl\b/; print "TRUE\n" if (@search); foreach (@search) { print "$_\n"; }