use strict; use warnings; ... foreach my $date (@dates) { foreach my $line (@{$maint_hash{$address}}) { my (@alljobs,@alljobids,@received); my %rtoa; runsingle($line,$date,\*OUT); } } ... } sub runsingle { ... some code that actually populates the declared variables... printjob($fh,$h,@foo); ... } sub printjob { my $fh=$_[0]; my $h=$_[1]; shift @_; shift @_; foreach my $key (@_) { print $fh $h->open('tr'); my $key2=$rtoa{$key}; print $fh $h->td(${$alljobs[$key2]}[2],${$alljobs[$key2]}[3],${$alljobs[$ key2]}[4]); my ($chopdate,$choptime,$junk)= split " ",${$received[$key]}[4]; $chopdate=~s/-201.//; print $fh $h->td("Ran at $choptime",$chopdate,${$received[$key]}[3]); print $fh $h->close('tr'); } print $fh $h->close('table'); }