in reply to substitutions on a single line
If you only want to change certain lines in a file, also take a look at Tie::File, which makes this very easy:
use strict; use Tie::File; tie @lines, 'Tie::File', $filename or die "Couldn't open $filename : $!"; for my $line (@lines) { if ($line =~ /LEU\b/) { s/ (.*)/$z3leu $z2leu $z1leu $1/ } };
That's it.
For an alternative, you could run Perl as a pipeline by redirecting the output of the following into a new file:
perl -pe "/LEU\b/ and s/ (.*)/$z3leu $z2leu $z1leu $1/"
|
|---|