in reply to question on Arrays

When you need to ensure that you have a unique list consider using
if (! $elements{$x}){ # we haven't seen it before $elements{$x}=1; } else{ print "Seen it\n"; } print join ",", keys(%elements);
As for your original question, sending an end of file to STDIN has no effect on while(1) you could read each line from STDIN until you hit an end of file.

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