#!/usr/bin/perl $keyword = shift @ARGV; $reverse = reverse $keyword; $line = 0; while(<>) { $line++; chop; #Add the word boundary to the search if (/\b$keyword\b/){ $_ =~ s/$keyword/$reverse/g; print "[$line] ", $_ , "\n"; } }