#!/usr/bin/env perl use strict; use warnings; my $report = print_query_results (); print "Here comes my report: \n$report\n"; exit; sub print_query_results { my @foo = ([9, 8, 7], [6, 5, 4]); my $blurb = 'Whatever'; my $report; my ($sql_id, $min_last_load_time, $buffer_gets); format REPORT = @|||||||||||||||@||||||||||||||||||||@||||||||||||||| 'SQL_ID', 'min_last_load_time','buffer_gets' @|||||||||||||||@||||||||||||||||||||@||||||||||||||| $sql_id, $min_last_load_time, $buffer_gets @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $blurb . open REPORT, '>', \$report; for my $aref (@foo) { ($sql_id, $min_last_load_time, $buffer_gets) = @$aref; write REPORT; } close REPORT; return $report; }