#!/usr/bin/perl -w use strict; use Getopt::Long; my ($verb, $obj) = $0 =~ m|([^/]+)-([^/]+)$|; my %defaults_verbs = ( 'create' => { foo => "foo", bar => "", }, 'update' => { foo => "", bar => "bar", }, #... ); my %defaults_objs = ( 'tap' => { baz => 42, }, 'fap' => { baz => 99, }, #... ); my %defaults_combined = ( 'create-tap' => { foo => "boo", baz => 13, }, #... ); # merge individual defaults hashrefs (order matters), e.g.: my $opts = { %{ $defaults_verbs{$verb} //{} }, %{ $defaults_objs{$obj} //{} }, %{ $defaults_combined{"$verb-$obj"} //{} }, }; GetOptions($opts, 'foo=s', 'bar=s', 'baz=i'); for my $opt (sort keys %$opts) { print "$opt=$opts->{$opt}\n"; } #### $ for name in create-tap update-tap ; do ln -s 882180.pl $name ; done $ ./create-tap bar= baz=13 foo=boo $ ./create-tap --foo=FOO bar= baz=13 foo=FOO $ ./update-tap bar=bar baz=42 foo= $ ./update-tap --baz=55 bar=bar baz=55 foo=