use Getopt::Std; my %opts; die "Usage $0 -m or -M #1 #2 #3..." if (!getopts( "mM", \%opts) || @ARGV !=0 || keys %opts != 2); CalculateMean() if $opts{m}; #@ARGV has just #1 #2 #3 ...now. CalculateMedian() if $opts{M};