# And now the hardcore, nonobvious solution, leaving the grep # loop prematurely and discarding the result : $index = 0; grep { goto DONE if ($_ eq $pos); $index++; 0 } @list; DONE: foreach $i (@list) { print( ("*"," ","|")[ 0 <=> $index-- ], " $i\n"); };