my $start = q{AA}; my $next = q{AB}; my $count = 0; my $value; foreach my $entry ( @{$strings} ) { if ( $count == $#$strings ) { $next = q{$}; } else { $next = q{\,\ } . _alpha_add($start); } $affiliation_string =~ m/$start\((.*?)\)($next)/s; $value = $1; $affiliation_key->{$entry} = $value; $start = _alpha_add($start); $next = _alpha_add($next); $count++; }