use warnings; use strict; use Getopt::Long; my $foo; GetOptions( "foo=s" => \$foo, ); if ($foo) { print $foo =~ /!(.*)/ ? "All but $1" : "Only $foo"; }; #### bash$ perl all-but-foo.pl --foo 4 Only 4 bash$ perl all-but-foo.pl --foo \!4 All but 4