use strict; my $string = "Required Not_Required Not_Required Required"; my @words = split(" ",$string); map {$_ =~ /^Required$/g;print "$&"}@words;