http://qs321.pair.com?node_id=147893

emcb has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I have written a sub called str_replace. This sub is supposed to work the same as the php function str_replace. Heres the code:

sub str_replace
{
  my( $find,$replace,$what ) = @_;
  $what =~ s/$find/$replace/i;
  return $what;
}

I then use this function to find x and replace it with y in z like so:

$string = str_replace("Hi", "Hello", "Hello My Name Is Elfyn");

This function only returns 'Hi' instead of 'Hi My name Is Elfyn'. Any help on why fellow monks.

Cheers,

Elfyn