my %hash = ( '$example' => 'This is an example ', '$comment' => 'This is a comment' ); open (FILE, 'file') or die ("Can't open file: $!\n"); while () { chomp; foreach $key (keys %hash) { s/$key/$hash{$key}/g; } print $_; } close (FILE);