in reply to Scalar assignment question

perldoc -f grep
... returns the list value consisting of those elements for which the expression evaluated to true. In scalar context, returns the number of times the expression was true.
In the first instance it sets scalar to the the number of matches.
In the second instance it actually only sets the value of $scalar to the first returned value as surrounding a scalar value in () puts the scalar into a list context.

print "Good ",qw(night morning afternoon evening)[(localtime)[2]/6]," fellow monks."