use strict; use warnings; my @novel_list = map { chomp $_; $_ } ; my $Bink_books = 'M1, M2, m3, m4, 6, m7, M9, m11, m13, 14, 17, m19, m21, M22, m23, m31, 35, 36, m37, m40, m41'; my $Quan_books = '0'; for my $books ($Bink_books, $Quan_books) { my @novels = split(/, /, $books); # $books is initialized for Quan even though the value is 0. my $first_book = $novels[0]; my $first_type = $first_book =~ /^M/ ? 'major' : $first_book =~ /^m/ ? 'mentioned' : undef; $first_book =~ s/\D//g; my $first_novel = $novel_list[$first_book]; # was my $first_novel = $novel_list->[$first_book]; print "$first_novel is the first novel the character was in.\n"; } __DATA__ Other source A Spell for Chameleon The Source of Magic Castle Roogna Centaur Aisle Ogre, Ogre Night Mare Dragon on a Pedestal Crewel Lye: A Caustic Yarn Golem in the Gears Vale of the Vole Heaven Cent Man from Mundania Isle of View Question Quest The Color of Her Demons Don't Dream Harpy Thyme Geis of the Gargoyle Roc and a Hard Place Yon Ill Wind Faun and Games Zombie Lover Xone of Contention The Dastard Swell Foop Up in a Heaval Cube Route Currant Events Pet Peeve Stork Naked Air Apparent Two to the Fifth Jumper Cable Knot Gneiss Well-Tempered Clavicle Luck of the Draw Esrever Doom Board Stiff Five Portraits Isis Orb Ghost Writer in the Sky