$ cat file.txt | perl -ne '(1..10)&&print' #### #!/usr/bin/perl my $counter; open A, 'file.txt'; while() { print if ($counter++ < 10); } close A;