format RECEIPT_TOP = Item Quantity Price -------------------------------------------- . format RECEIPT = @<<<<<<<<<<<<<<<<<<<<< @<<<<< @####.## @format_row . for my $row_ref ( @$cartItemsRef ) { @format_row = @$row_ref; write RECEIPT; # this writes to the filehandle RECEIPT }