On Jun 16, Kevin Zhang said: >For the following string: > >"uuuu axyzb oooo cxyzd vvvv" > >What is the command to extract the substrings with "xyz" in them? In this >case, I'd like to get two strings "axyzb" and "cxyzd".
Well, you could do: my @matches = grep /xyz/, split ' ', $string; Let me break that up into multiple statements: # split $string on any amount of whitespace # @fields will be ('uuuu', 'axyzb', 'oooo', 'cxyzd', 'vvvv') my @fields = split ' ', $string; # now filter into @matches any element in # @fields that matches the pattern /xyz/ # @matches will be ('axyzb', 'cxyzd') my @matches = grep /xyz/, @fields; -- Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ CPAN ID: PINYAN [Need a programmer? If you like my work, let me know.] <stu> what does y/// stand for? <tenderpuss> why, yansliterate of course. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>