in reply to formatting output

I still don't understand what your input data might look like, but is this closer to your output example?

#!/usr/bin/perl -w use strict; use warnings; my ( $county, $year_x, $yr_tot, $production ); my $result = &make_table; print $result; sub make_table { open YEARLY, '>', \$production; print YEARLY " 2001 2002 2003 2004 \n"; while ( <DATA> ) { ( $county, $year_x, $yr_tot ) = split ' ', $_; if ( $year_x eq "1" || "2" || "3" || "4" ) { $year_x += $yr_tot; write YEARLY; } } return $production; } format YEARLY = @<<<<<<<< @<<<< $county, $year_x . close YEARLY; __DATA__ McMahon 1 9000 McHardy 2 8000 Moonlit 3 7000 Murphie 4 6000

Returns:
2001 2002 2003 2004 McMahon 9001 McHardy 8002 Moonlit 7003 Murphie 6004


No writing to a disk file until you need to...