in reply to extract whole sentence after a match of a word

use strict; use warnings; my @all_lines = <DATA>; # get the lines that match the word 'number' my @lines = grep /number/, @all_lines; print "Lines that matched\n"; print for @lines; # get and highlight the lines that match the word 'number' my @bold = map { $_ =~ /number/ and s/number/<b>number<\/b>/g ? $_ : ( +); } @all_lines; print "\nHighlighted word\n"; print for @bold; __DATA__ number.................... ..................... ......number.............. ......................... ..................number

outputs:

Lines that matched number.................... ......number.............. ..................number Highlighted word <b>number</b>.................... ......<b>number</b>.............. ..................<b>number</b>