Ok, I think I see the problem. I re-wrote your script a little (watch for line breaks), and you should be able to see what the problem is when you run it. Your substitution isn't doing what you think it's doing. In the future it always helps to add these kinds of "debug lines" when it seems like your variables aren't doing what they're supposed to, or use an actual perl debugger to see what is happening in real time.
You could try replacing '$pattern' with '$1' in the substitution, but depending on how complex your regexes are, you might not get the results you want. In the example below you could end up replacing all instances of 'ch', when that's clearly not was intended. However, if you just want to find all instances of a text string and replace it, it will work fine to use $1. ####################################### use strict; use warnings; $^I ='_old'; print "\n\n"; print "Enter a pattern to look for,\n"; print "and some text to replace it with.\n\n"; print "PATTERN: "; my $pattern = <STDIN>; chomp($pattern); print "REPLACEMENT: "; my $replacement = <STDIN>; chomp($replacement); print "\n\n"; while(<>){ my $choice; if(/$pattern/gi){ print STDOUT "Pattern Found!\n\n"; print STDOUT "\t\$_ => $_\n"; print STDOUT "\t\$1 => $1\n\n"; print STDOUT "\tType \"s\" to confirm substitution,\n"; print STDOUT "\t or press any other key to cancel: "; $choice = <STDIN>; chomp($choice); print STDOUT "\n\tCOMMAND: s/$pattern/$replacement/gi if \$choice eq \"s\"\n"; s/$pattern/$replacement/gi if $choice eq "s"; print STDOUT "\n\n"; } print; } ########################################## OUTPUT: C:\Documents and Settings\tjohnson\Desktop>replace.pl cppb.txt Enter a pattern to look for, and some text to replace it with. PATTERN: Te([^ ]+).*support REPLACEMENT: sticular Pattern Found! $_ => Tech Support $1 => ch Type "s" to confirm substitution, or press any other key to cancel: s COMMAND: s/Te([^ ]+).*support/sticular/gi if $choice eq "s" ________________________________________ From: Adriano Allora [mailto:[EMAIL PROTECTED] Sent: Tuesday, January 03, 2006 10:03 AM To: Timothy Johnson Subject: Re: about eval and stdin hi, Il giorno 03/gen/06, alle 18:16, Timothy Johnson ha scritto: I think when you include the parentheses in your pattern $1 is being set to the value inside the partentheses. It's as if you typed: if(/(dir)ectory/gi) which will set $1 to 'dir', which is probably not what you want. ehm, instead it's exactly what I want (selecting a part of the pattern as substitution). My problem is that the script sets $1 = "$1" and I ignore why. thanks, alladr I think you can avoid this if you change the line to: if(/($pattern)/gi) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>