use strict; use warnings; my $para = 'This is a wilma line barney is on this line but this line ends with fred ** this line has barney in the middle ** and a final dino line'; my $count = 0; for my $line (split /\n/, $para) { printf "line %d: >%s< -- barney %sfound\n", ++$count, $line, $line =~ /^\s*barney/ ? '' : 'not '; }