title: perl printing table output
body: <p>I am trying to print output in tabular format.</p>
  
  <p>my Script:</p>
  
  <pre><code>use strict;
  my @heading=("FN","SN","BP","SUBBN","LgcBT");
  my @values=("1","0","Front","Mother Board","MIU");
  print "\n\n";
  &amp;HEADING;
  print "\n";
  &amp;VALUES;
  print "\n\n";
  
  sub HEADING {
      foreach (@heading) {
          my $lgth1=length($_);
          printf "%3s","| ";
          printf "%${lgth1}s",$_;
      }
  }
  
  sub VALUES {
      foreach (@values) {
          my $lgth2=length($_);
          printf "%3s","| ";
          printf "%${lgth2}s",$_;
      }
  }
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code> | FN | SN | BP | **SUBBN** | LgcBT
  
   | 1 | 0 | Front | **Mother Board** | MIU
  </code></pre>
  
  <p><strong>I need to print output in a way that if value is longer than heading then it automatically adjusts length of heading to that of value.</strong></p>