in reply to how to do replace more then one matches?

You mean something like this?:

use warnings; use strict; my $li = "abbjghfg table 1 vinoth figer table2"; my $new_str; while ( $li =~ m/(.+?)(table.?\d)/gc ) { $new_str .= $1 . '<aid=' . $2; } print $new_str, $/; #abbjghfg <aid=table 1 vinoth figer <aid=table2
Update: Why to avoid using $&, $`, or $' in your program

If you tell me, I'll forget.
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author unknown to me