my %check_dispatch = ( 2 => sub { ... }, # or better, define in named subs and, => \&check1, etc 3 => sub { ... }, 4 => sub { ... }, 5 => sub { ... }, ); my $pw = $_; my $index = min( (length $pw)/4, 5); if ($check_dispatch{$index} and 'CODE' eq ref $check_dispatch{$index}) { die if not $check_dispatch{$index}->($pw); }