title: How can I pad part of a string with spaces, in Perl?
body: <p>Which version would you prefer?</p>
  
  <pre><code>#!/usr/bin/env perl
  use warnings; 
  use strict;
  use 5.010;
  
  my $p = 7; # 33
  my $prompt = ' : ';
  my $key = 'very important text';
  my $value = 'Hello, World!';
  
  my $length = length $key . $prompt;
  $p -= $length; 
  </code></pre>
  
  <p>Option 1:</p>
  
  <pre><code>$key = $key . ' ' x $p . $prompt;
  </code></pre>
  
  <p>Option 2:</p>
  
  <pre><code>if ( $p &gt; 0 ) { 
      $key = $key . ' ' x $p . $prompt;
  }
  else {
      $key = $key . $prompt;
  }
  </code></pre>
  
  <hr>
  
  <pre><code>say "$key$value"
  </code></pre>