next up previous contents index
Next: Sorting Up: Comparisons Previous: Numerical comparison   Contents   Index

String comparison

For comparing strings, you can use Note that string comparisons respect the case - a string $var1 = 'NO' is not equal to a variable $var2 = 'no'. If you want to compare two strings and not worry about the case, the operators uc (for converting a string to all upper-case) and lc (for converting a string to all lower-case) may be useful:
my $answer = 'YES';
if (lc $answer eq 'yes') {
  print "You answered in the affirmative";