Mega Code Archive

 
Categories / Perl / String
 

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";