#!/usr/bin/env perl use strict; use warnings; my $t='(header)'; my $l=0; my $c=0; while () { if ( $_ =~ /^COPY (.*) FROM stdin;$/ ) { $a = int(($c / $l) + 0.5); print "$t : $l lines (average : $a chars)\n"; $t=$1; $l=0; $c=0; } else { $l=$l+1; $c=$c+length($_); } } $a = int(($c / $l) + 0.5); print "$t : $l lines (average : $a chars)\n";