You need to do 2 things:
- Create a mapping local to a specific buffer by using the
<buffer> option for noremap.
- Load the mappings for just a specific filetype.
This can be done via an autocmd and FileType event in your .vimrc like so:
autocmd FileType perl noremap <buffer> <F5> :!perl %:p<cr>
The other way option is by creating a filetype plugin. (see :h ftplugin for more details)
A simple example is do create a file named, ~/.vim/ftplugin/perl.vim and place your mappings inside like so:
nnoremap <buffer> <F5> :!perl %:p<cr>
I personally lean more towards the ftplugin approach but having a everything in your .vimrc file can be nice.
For more help see:
:h :au
:h FileType
:h map-local
:h ftplugin