#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my @test1 = ("1","2","3","0","0","0","0","t","5","8","0","0","56"); my @test2 = ("0","0","0","z","i","p","y","u","9","9","8","9","10","58"); @test1 = map { $test1[$_] eq '0' ? $test2[$_] : $test1[$_] } 0 .. $#test1; print Dumper \@test1;