use strict; use warnings; use Data::Dumper; my @skip_idx = (6,13,42,66,69); my @array = (); my @invarray = (); my $idx = -1; foreach my $str ('aa'..'zz') { ++$idx; if (grep { /^$idx$/ } @skip_idx) { # could use List::Util::any here push @invarray, $str; print "skipped '$str' (index of $idx)\n"; } push @array, $str; } print Data::Dumper::Dumper(\@invarray);