#!/usr/bin/env perl use strict; use warnings; use autodie; my $in_file = 'pm_11132903_input.txt'; my $out_file = 'pm_11132903_output.txt'; my $format = ".%s(%s),\n"; { open my $in_fh, '<', $in_file; open my $out_fh, '>', $out_file; while (<$in_fh>) { if (/^(rist_top_\w+)/) { printf $out_fh $format, ($1) x 2; } else { print $out_fh $_; } } } # Just for testing and demonstration print "*** INPUT: $in_file ***\n"; system cat => $in_file; print "*** OUTPUT: $out_file ***\n"; system cat => $out_file;