my @actions = ( { match => sub { $_[0] =~ /^(\w*)\.(\d*)$/; }, type => "inventory", action => &add_inventory; }, { match => sub { $_[0] =~ /^maimed(\w*)$/; }, type => "maimed", action => &handle_maimed; }, { match => sub { $_[0] }, type => "default", action => sub { print "I cannot handle ", $_[0]; } } ); # much later foreach my $file ( @filelist ) { foreach my $action ( @actions ) { if ( my @parts = &{ $action->{ match } }( $file ) ) { print "Am doing $action->{ type } on $file\n"; &{ $action->{ action } }( @parts ); last; } } }