my @newfiles = ("new_one.txt", "old_one.txt", "old_two.txt", "new_two.txt"); my %oldfiles; $oldfiles{"old_one.txt"}="this is the old one"; $oldfiles{"old_two.txt"}="this is the old two"; $oldfiles{"old_three.txt"}="this one should be deleted"; $oldfiles{"new_two.txt"}="this one has been added already"; my %newfiles; foreach (@newfiles){ $newfiles{$_}++; next if exists $oldfiles{$_}; print "have to add $_\n"; } foreach (keys %oldfiles){ next if exists $newfiles{$_}; print "have to remove $_\n"; }