Skip to content

Replace a string using regular expressions in Perl

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;
Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay
  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

Post a Comment

Your email is never published nor shared. Required fields are marked *
*
*