#!/usr/bin/perl use strict; use warnings; use Getopt::Long qw( :config posix_default gnu_compat bundling no_auto_abbrev no_ignore_case ); my $column=1; @ARGV = grep $_ !~ /\A--c\b/, @ARGV; #if( grep s/\A--c\b=?.*//, @ARGV ){ $column = 100 }; # \b can be replaced with (?!o) for finer resolution #if( grep s/\A--c(?!o)=?.*//, @ARGV ){ $column = 100 }; GetOptions( 'column|c=i' => \$column, ) or die; print "\$column is $column\n"; die if $column < 1; __END__ # grep filtered $ ~/Desktop/gol.pl --c 2 --c=2 --c= 2 --c = 2 $column is 1 # grep substitution conditional $ ~/Desktop/gol.pl --c= 2 --c = 2 --c 2 --c=2 $column is 100