use strict; my $string = "Required Not_Required Not_Required Required"; while($string=~/\bRequired\b/gi){ print "$&\n";##Here it will print only required text with non word character before and after }