When it needs to create various choises according to someone variable it’s reasonable to build a shitch block:
sub test {
my $var = shift;
SWITCH: for($var) {
/^1$/ && do { do something for case 1 ... ; last SWITCH;};
/^2$/ && do { do something for case 2 ... ; last SWITCH;};
/^3$/ && do { do something for case 3 ... ; last SWITCH;};
}
}
But what will happend if you’ll decide to swap case 2 and case 3? You should make changes in your code.