use strict; use warnings; my @arr = qw{ 1 1 0 2 0 1 3 0 0 4 1 1 5 7 }; sub { local $" = q{,}; print qq{@{ [ grep defined, map shift, 1 .. 3 ] }\n} while @_; }->( @arr ); print qq{@arr\n};