my %transformation_by_filetype => ( "c" => { "foo" => qq{ You had a foo. }, "foo" => qq{ Bar is great. }, }, ); Then run something like this: #! /usr/bin/perl -w use strict; for my $file (@ARGV) { my $filetype = determine_filetype($file); my $transformation = $transformation_by_filetype{$filetype}; rename($file, "tmp.$$") or die "Can't rename $file to tmp.$$: $!"; open (IN, "<", "tmp.$$") or die "Can't read tmp.$$: $!"; open(OUT, ">", $file) or die "Can't write $file: $!"; while (my $line = ) { print OUT $line; for my $pattern (keys %$transformation) { if ($line =~ /$pattern/) { print OUT $transformation->{$pattern}; } } } } sub determine_filetype { my $filename = shift; $filename =~ s/.*\.//; return $filename; }