my %hash = ( '$example' => 'This is an example ', '$comment' => 'This is a comment' ); open (FILE, 'file') or die ("Can't open file: $!\n"); while () { chomp; if (exists $hash{$_}) { print $hash{$_}; } else { print $_; } } close (FILE); #### 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); #### my %hash = ( '$example' => '$comment is a variable', '$comment' => 'this is a comment' );