$li ="abbjghfg table 1 vinoth figer table2"; $f=$li; while($f=~m/table[ ]([0-9])+|table([0-9])+|fig[ ][0-9]+|fig[0-9]+/g) { $f = $'; $match_key=$&; $front=$`; $rep=$front."