Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Replace a string using regular expressions in Perl

Answer:

The following code demo how to replace a string in Perl,

my $s = 'love foobar';

$s =~ s/love/hate/g;

print $s;
  1. Match a string using regular expressions in Perl
  2. Capturing group difference in Basic Regular Expressions (BRE) and Extended Regular Expressions (ERE)
  3. Search and replace string in file using Perl
  4. How to replace a string in a file using Perl
  5. Trim a string using Perl

Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>