# splice of the residue array after the first matching element # note the last, we finish the loop once we found $sorted_nums[0] my $pos = 0; foreach(@start_incline) { (@inline = @start_incline[$pos+1 .. $#start_incline], last) if ($_ == $sorted_nums[0]); ++$pos; } # do work with it foreach(@incline) { print $_ . " "; }