$, = $/; $a[$_] = ++$line while <>; print map $a[$_] || (), $[ .. $#a; #### $, = $/; undef @a[<>]; print grep exists $a[$_], $[ .. $#a;