You must've not only removed the my
, but the brackets as well. It was the brackets, mind you, that are the key here.
Including brackets means that you're assigning a list to a list, in this case, the result of the grep
operation into a list containing the variable $ok
. Thus, the first thing grepped goes into the first variable, and you get "Some String".
If you want to know how many things you got, you need to force a list to scalar conversion. That might sound fancy, but it's just a way of saying you want to assign the list directly to the variable instead of to a list of variables. No brackets. If you're a bit fuzzy, here's some examples;
my @list = ("A","B","C");
my ($var) = @list; # $var becomes "A"
my $var = @list; # $var becomes 3
my ($var) = scalar(@list); # $var becomes 3
my $var = scalar(@list); # $var becomes 3 (same idea)