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);