s/foo/bar/ s/(fo)o/bar$1/ #### while(my $line = ) { chomp; eval "\$string =~ $line; 1" or die $@; }