my $group; if ($teststring =~ /^\[(\w+)]/) { $group = $1; } elsif ($teststring =~ /^(\w+)/ { $group = $1; ...