Plural format and ternary operator
#!/usr/bin/perl
use warnings;
use strict;
my @words = split ('\s+', <>); #read some text and split on whitespace
my $words = scalar (@words);
print "There ", ($words == 1)?"is":"are"," $words word", ($words == 1)?"":"s"," in the text \n";
Related examples in the same category