title: Modify the last two characters of a string in Perl
body: <p>I am looking for a solution to a problem:</p>
  
  <p>I have the NSAP address which is 20 characters long:</p>
  
  <pre><code>39250F800000000000000100011921680030081D
  </code></pre>
  
  <p>I now have to replace the last two characters of this string with <code>F0</code> and the final string should look like:</p>
  
  <pre><code>39250F80000000000000010001192168003008F0
  </code></pre>
  
  <p>My current implementation chops the last two characters and appends <code>F0</code> to it:</p>
  
  <pre><code>my $nsap = "39250F800000000000000100011921680030081D";
  
  chop($nsap);
  
  chop($nsap);
  
  $nsap = $nsap."F0";
  </code></pre>
  
  <p>Is there a better way to accomplish this?</p>