$str = "===test==="; if( $str =~ /(\w+)/ ) { print "[$str] ($1)\n"; substr( $str, 5, 2, 'mp' ); print "[$str] ($1)\n"; } __END__ [===test===] (test) [===temp===] (test)