When you are using grep, you are dealing with lists. grep takes input as a list, and produces a list as output.
Whenever an array is evaluated in scalar context (such as assigning to a scalar variable), it returns its length. Whenever it is evaluated in list context, it returns the array itself. In this case grep works in the same way as an array, returning the length of the list returned from grep when evaluated in scalar context.
my $pname = grep {
!/create/i&&!/or/i &&!/replace/i&&!/package/i&&!/body/i&&!/as/i
} split / /, $str1[0]);
print $pname , "\n";
will return the size of the list returned from grep because $pname is a scalar variable.
my ($pname) = grep {
!/create/i&&!/or/i &&!/replace/i&&!/package/i&&!/body/i&&!/as/i
} split / /, $str1[0]);
print $pname , "\n";
Will return the first element of the list, because the assignment is performed in list context (notice the parens around $pname).
Here is a brief overview of context: http://perlmaven.com/scalar-and-list-context-in-perl