#!/usr/local/bin/perl -w use Getopt::Long; use Data::Dumper; use strict; # Parse command line arguments and assign corresponding variables GetOptions ( 'm|monitor=s' => \( my $MON = undef ), ); unless ( defined $MON ) { print < Example: $0 -m ADD,DELETE $0 -m remove,delete Note: No space between comma and commands EOF ; exit(1); } my @options = map { uc } (split /,/, $MON); # verify input commands my @allowed_commands = qw/ ADD REMOVE DELETE /; foreach my $opt (@options) { die "Unknown command $opt" if ! scalar grep $opt eq $_, @allowed_commands; } my $monitor_commands = join '|', @options; # DEMO - give it a little test in action monitor... # @actions simulates a sequence of commands my @actions = qw/ ADD ADD REMOVE ADD DELETE FREE /; foreach my $action (@actions) { if ($action =~ /($monitor_commands)/) { print "Command [$action] is monitored\n"; } else { print "Command [$action] is NOT monitored\n"; } }