Perl 并没有switch结构的语法,但可以使用标签与判断实现switch结构。

use strict;

my $var = 5;

SWITCH: {
  $var == 1 && do { print "$var = 1"; last SWITCH; };
  $var == 2 && do { print "$var = 2"; last SWITCH; };
  $var == 3 && do { print "$var = 3"; last SWITCH; };
  print "$var is not equal with 1 or 2 or 3";
}