# Regular expressions to apply my $a_regexes = [ qr/^([^\s]+)/, qr/-address="([^"]+)"/, qr/-port="([^"]+)"/, qr/-nick="([^"]+)"/, qr/-password="([^"]+)"/, qr/-prefix="([^"]+)"/, qr/-auto_connect="([^"]+)"/, ]; # Construct an array of resulting regex captures my @results = ( ); # Save each pattern (returning if missing from regex) foreach my $regex (@$a_regexes) { if ($msg !~ /$regex/) { return 0; } push @results, $1; } # Assign to the desired variables my ($alias, $address, $port, $nick, $password, $prefix, $auto_connect) = @results;