replacing sed with perl in few cases