#!/usr/bin/perl use warnings; use strict; my %refspecies = ( HOMSAP => 'Homo sapiens', MUSMUS => 'Mus musculus', CIOINT => 'Ciona intestinalis' ); my @species =('HOMSAP','MUSMUS','-CIOINT'); my @duplicate = @species; # Incorrect working code print "Before processing: @species\n"; foreach (@species) { /^-?(.+)$/; $_ = $1; unless (exists $refspecies{$_}) { # Species not in list die "$_ is not in the species table\n"; } } print "After processing: @species\n"; #Correct working code #Duplicate run with minor code adjustment print "Before processing: @duplicate\n"; foreach (@duplicate) { /^-?(.+)$/; #$_ = $1; Removed this line and changed $_ below in $1. This shouldn't matter because I am manipulating $_ in the code above and NOT @species, but somehow it does! unless (exists $refspecies{$1}) { # Species not in list die "$1 is not in the species table\n"; } } print "After processing: @duplicate\n"; #Output is: #Before processing: HOMSAP MUSMUS -CIOINT #After processing: HOMSAP MUSMUS CIOINT #Before processing: HOMSAP MUSMUS -CIOINT #After processing: HOMSAP MUSMUS -CIOINT # Look at @species element 3. Why is @species changed?