--On Freitag, 05. Oktober 2001 15:05 -0700 "AMORE,JUAN (HP-Roseville,ex1)" <[EMAIL PROTECTED]> wrote:
> > Hello Anyone! > I have the below script but it doesn't match just the words containing the > letter p. > Enstead I get "And then Joppy had a puppy named soapy" > > Is there a way to modify this script a bit for out put to say; > "Joppy puppy soapy" > > Many Thanks! > > while (<>){ > print if (m/p/); > } > You're reading in line by line and asking perl to print a *line* if it contains the letter "p", not a word. That's why you get the entire line printed, including words that don't contain "p". my $filename = "somefile";# your file name open (FILE, "<$filename") || die ("Can't open $filename: $!"); while (<FILE>) { my @words = split / /;#assumes words in line are separated by a single space foreach my $word (@words) { if ($word =~ /p/) { print "$word\n"; } } } close (FILE); Birgit Kellner -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]