perl -e 'for $i (1..9){$x = $i, next if $i == 5;print $i};END{print "\n$x\n"}' Output: 12346789 5