sub reader { foreach my $rows (@$data) { my %GenericData; @GenericData{ @rawFields } = @$rows; # NOTE added push @rawRecords, \%GenericData; } return \@rawRecords; #### my $rows = reader($mysqlFilename); ...in reader my $json = encode_json($hashref, { lastname => JSON_TYPE_STRING, firstname => JSON_TYPE_STRING, age => JSON_TYPE_INT} ); ...and I return $json which is the single record.