use strict; my ($row, $col) = (0, -1); my %TABLE; my @COLUMNS = ('Period', 'Code', 'Name', 'Handle', 'Date', 'From', 'To'); my @VARIABLES = qw/$colPeriod $colCode $colName $colHandle $colDate $colFrom $colTo/; my %Header = ( columns => \@COLUMNS, variables => \@VARIABLES, table => \%TABLE, heading => 'true', row => $row, column => $col, ); BuildHeader(\%Header); sub BuildHeader { my ($header_ref) = @_; my $TABLE = $header_ref->{table}; my $row = $header_ref->{row}; my $col = $header_ref->{column}; #columns and variables array must be equal if ( scalar @{$header_ref->{columns}} != scalar @{$header_ref->{variables}} ) { return; } foreach ( @{$header_ref->{columns}} ) { $TABLE{table}[$row][++$col]{value} = $_; $TABLE{table}[$row][$col]{heading} = $header_ref->{heading}; #Populate each variable in @variables with $col value ++$col; #return the variables } }