use List::Util qw( reduce ); my %ops = ( add => sub { reduce { $a + $b } @_ }, multiply => sub { reduce { $a * $b } @_ }, # etc ... ); my $op = shift or die "You must specify an operation followed by numbers.\n"; die "Non-numeric input.\n" if grep /\D/, @ARGV; die "Invalid operation.\n" unless exists $ops{$op}; print "$op (@ARGV)= ". $ops->(@ARGV) . "\n";