perl -pe 'BEGIN { $/ = "#" } exit if $. > 500' input-file