my $ii=1; for(my $k=1;$k<$lt;$k++){ if ($k == $loc[$ii]){ print "" .$text[$k] . ""; $ii++; } }