#!/usr/bin/perl -w use strict; my %keywords = ( foo=>'/foo.html', bar=>'bar.html', cult=>'http://perlmonks.org' ); my $textfile ="/file/to/link"; open TEXTFILE, $textfile or die "Yikes! $textfile won't open: $!\n"; my $data; { local $/; #sets input list separator to undef #so we can 'slurp' the file in $data = ; } close TEXTFILE; foreach (keys %keywords) { my $url = $keywords{$_}; # EDITED ... I'd forgotten to escape # the / in front of the closing # credit to Albannach $data =~ s/($_)/$1<\/a>/g; } # now do something with $data