in reply to Re^2: Help with split() function
in thread Help with split() function

Well, here's what i would do, and presuming i can still read the output is tested and correct:

#!/usr/bin/perl -w use strict; while (<DATA>) { my @line = split (); foreach my $word (@line) { if ($word =~ /P/i) { print "$word\n"; } } } __DATA__ CPAN stands for comprehensive Perl Archive Network. ^ and $ are used as anchors in a regular expression. /pattern/ is a pattern match operator. Perl is very easy to learn. Enter 'H' or 'h' for help.

Why?

Your use of split is fine. But you need to loop thru your array:
  • line 6: if it doesn't make sense, figure it out
  • line 7: ditto
  • line 8: ditto