in reply to Not printing the values outside the while loop

Just my thoughts on your post:

  1. use strict;
  2. use warnings;
  3. use Carp; and then call croak() instead of die(). Makes it easier to debug as soon as the code moves into a sub.
  4. one letter variable names are not a good idea, except in things like iterator counters, e.g. for(my $i = 0; $i < 10; $i++)
  5. $a and $b are reserved variable names, used by sort(). Do not use them for anything else.
  6. Unless your variables end in a line break, the print statements wont show up immediately on the command line, because buffered IO.
  7. When i do file operations, i usually chomp() every line, then add linebreaks explicitly to the output when required. Makes it easier to understand the code.
  8. Not sure why you are opening $ofh51 for writing. You don't write to it.
  9. Both the example text file and the example output should be in their own code tags for easier reading as well as downloading.
  10. Personally, i also prefer singular/plural naming of variables. So, for example it would be @results. When accessing an element of that, it would be $results[1], because its "one of many". On the other hand, an iterator would be singular, something like foreach my $result (@results). But that's just me...

perl -e 'use Crypt::Digest::SHA256 qw[sha256_hex]; print substr(sha256_hex("the Answer To Life, The Universe And Everything"), 6, 2), "\n";'