#!/usr/bin/perl use strict; use warnings; my $file = $ARGV[0] || 'export.dat'; open(my $fh, '<', $file) or die "Unable to open '$file' for reading: $!"; my @buffer; while (<$fh>) { if (/^1(\d+.*)/) { # Start of new record output_data(@buffer) if @buffer; # process last record if not first @buffer = $1; # put new line in buffer } else { push @buffer, $_; # Add line to buffer } } output_data(@buffer) if @buffer; # Process last record if present sub output_data {}