This is a recipe for creating a flexible string split on an argument that is passed into a script.  Suppose we have a script that is using GetOpt::Long to obtain user input specifying a single entity or a list of entities.  The user can use his/her own delimiters on the command line to separate each entity.  For this recipe, we use GetOpt::Long to accept an argument --qtype or -q in the form of a string.  A user may type any of the following:

my_script.pl -q A,NS,SOA,SRV
my_script.pl -q A NS SOA SRV
my_script.pl --qtype A,NS,SOA,SRV
my_script.pl --qtype A NS SOA SRV

The examples above show that the user can pass either -q or --qtype followed by a string.  The strings shown above use different delimiters, one space-delimited, and the other comma-separated.  In our script, suppose we need to build a list from the string inputted by the user, and suppose that we want to offer flexibility in allowing the user to use what ever delimiter he/she wants when entering the data.  Our split command to separate this string argument for the above program needs to be capable of splitting on either spaces or commas.  Here is an example of using the perl split function to split using multiple REGEX patterns:

GetOptions ( 'qtype=s' => \$qtype );
{
	local $\ = undef;
	@qtypes  = split(/[\s+|,]/,$qtype);
}

This script snippet will capture the inputted argument into the variable $qtype. This variable is then split on either space or commas to generate the @qtypes array list.

NOTE: $\ is locally set to undef in the above example. This is the output record separator for the print operator.  When the block or {} is executed the $\ will return to its previous setting.

Should you need to make the input argument even more flexible you could add many more regex patterns in our split function.  We might add other delimiters such as the ^ or ; or : to make a more flexible input argument to our script. 

GetOptions ( 'qtype=s' => \$qtype );
{
	local $\ = undef;
	@qtypes  = split(/[\s+|,|^|;|:]/,$qtype);
}

This solution requires that the user supply a consistent format or delimiter, i.e. this solution will not work if the user supplied a string with mixed delimiters such as:

my_script.pl -q NS,A,PTR SOA SRV,TSIG