foreach $file (@files) { $file_new = $file; open(IN, $file_new); $content = ; $content =~s/xhtml/wml/g; #...do lots more swopping here... $content =~s/

/

/g; # now i want to replace /textarea/ below with /input/ and also take /<%bar%>/ and put it into /foo/ # trying something like this- doesn't work while ($content =~ m/\(\)/sg) { my $match = $1; $match =~ s/\n//g; print " MATCH $match\n"; if($bar=~m/<%*?%>/){ $foo =~ m/foo/; $value_of_bar = $bar; # how to get $bar into $foo? $content =~ s/$foo/$bar/g; } } # write $content to file open(OUT, ">$ARGV[1]/$file_new") || die "cannot open $ARGV[1]/$file_new"; print $content; print OUT $content;