in reply to if or switch?

I'd go with a lookup-table. Since you can look up directly in a hash table, a list will have to do...

my @keys = ( [ "key1" => sub { handle_key1 } ], # inline anony sub [ "key2" => \&handle_key2 ], # use a named function [ "key3" => sub { ... } ], # ... ); use List::Util qw(first); # find the entry my $data = first { index($mystring, $_->[0]) >= 0 } @keys; # call the code $data->[1]->();