Replace first 5 characters of $string with 'bye' and assign substring that was replced to $substring : Replace « String « Perl






Replace first 5 characters of $string with 'bye' and assign substring that was replced to $substring

   


#!/usr/bin/perl

use warnings;
use strict;

my $string = "hello there\n";
print "The original string: ", 'hello there\n', "\n\n";


my $substring = substr( $string, 0, 5, "Bye" );

print "The string after the replacement: $string";
print "The substring that was replaced: $substring\n\n";

   
    
    
  








Related examples in the same category

1.Replace function based on substr function
2.Replace function based on the length