#!/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"; } #### Benchmark: timing 100000 iterations of index, re... index: 4 wallclock secs ( 3.54 usr + 0.00 sys = 3.54 CPU) @ 28248.59/s (n=100000) re: 7 wallclock secs ( 6.98 usr + 0.00 sys = 6.98 CPU) @ 14326.65/s (n=100000)