perl -ne "print if /pattern/ and $i++ < 100" file.txt