# Define the tokens we wish to extract my @tokens = qw( address port nick password prefix auto_connect ); # First token is a special case my $alias = ($msg =~ /^(\S+)\s*/)? $1: ""; $alias or return 0; # Construct an array of resulting regex captures my @results = ( ); # Construct the regex from each token, and capture the value foreach my $token (@tokens) { ($msg =~ /-${token}="([^"]+)"/ or return 0; push @results, $1; } # Assign to the desired variables my ($address, $port, $nick, $password, $prefix, $auto_connect) = @results;