# Exit after first match perl -ne 'print; last if /foo/' file