#!/usr/bin/perl use strict; use warnings; my @full_authors = ( "Smith, John", "Smith, John Ronald", "Johnson, James", "James, Ray Jack", "Van der Burg, Jon", "O'Neil, Sarah" ); my @authors = ( "Smith J", "Jackson J", "James RJ", "Van der Burg J", "O'Neil S" ); # Results should be: # Smith J = Smith, John # Jackson J = Jackson J # James RJ = James, Ray Jack # Van der Burg J = Van der Burg, Jon # O'Neil S = O'Neil, Sarah foreach my $author (@authors) { print "$author = "; # Regex rules # Last ' ' before all-uppercase word should become ', ' # Every singular or grouped capital letter # (i.e. F or RJ) should become F(.*) or R(.*) J(.*) # What I have so far $author =~ s/ (\w+?)\p{IsUpper}/, $1\(\.*\)/; print "[ $author ] : "; if ( my ($match) = ( grep $_ =~ /$author/, @full_authors ) ) { $author = $match; @full_authors = grep { $_ ne $match } @full_authors; } # end-if print "$author\n"; } # end-foreach exit;