in reply to Searching and replacing text

WARNING: Untested, incomplete code ahead

I would create this script in form of a filter:
#!/usr/bin/perl -i.bak :
and would make the file_a an option so that you can do it like this:
$ ./myfilter -i file_a file_b
This would then create a new file_b and preserve a backup file_b.bak.

First thing you should do in the filter is find all the things you'd like to replace in file_b (should it be more than just one) and store it in a hash:
while (<filea>) { if ( this is a line i want ) { s/[\015\012]+$//; # Just to remove any CR/LF my($router,$site)= split /,/,$_,3; $replace{$router}= $site; } } my $replacements= '\b('.join('|',keys %router).')\b';
After that you have a list of texts to search for as keys %replace and the replacement as $replace{...}. You also have a string of the form: \b(router1|router2...|routerN)\b that will be used in a regular expression.

When you've done with that, simply read and write what ever comes through <> replacing what you need:
my $symbol; while (<>) { if (my $hit/^SYMBOL: $replacements/i ... /^END SYMBOL/i) { if ($hit==1) { $symbol=$1; } else { s/^(Parent Submap:).*/$1 $replace{$symbol}/; } } print; }
That's it.