You can use Data::Dumper to print out a stringified representation of data whenever you want, error condition or not. Here is an answer to another SoPW with an example of Data::Dumper being used to visualise the data that the program has constructed. Note that the output produced is valid Perl code which could be printed to a file, read back in by another script and evaled to re-create the data.