my $foo = "[hello]"; my $bar = "agabaga[hello]zoomzoomzoom"; my $buzz = "goodbye"; $bar =~ s/$foo/$buzz/gi; print "\n$bar\n";