1  #!/usr/local/bin/perl -w
  2  
  3  print "Enter a temperature (e.g., 32F or 100C):\n";
  4  $input = <STDIN>; chomp( $input );
  5  
  6  if ( $input =~ m/^\s*([-+]?\d+(\.\d*)?)\s*(C|F)\s*$/i ) {
  7    $temp = $1; $type = $3;
  8    if ( $type =~ m/c/i ) {
  9      $celsius = $temp;
 10      $fahrenheit = ( $celsius * 9/5 ) + 32;
 11    } else {
 12      $fahrenheit = $temp;
 13      $celsius = ( $fahrenheit - 32 ) * 5/9;
 14    }
 15    printf "%.2f C = %.2f F\n", $celsius, $fahrenheit;
 16  } else {
 17    print "Expecting a temperature, not \"$input\"\n";
 18  }