#!/usr/bin/perl use strict; use warnings; my @cases = ( '2+(', '2(', '2+3', ); for my $case ( @cases ){ $case =~ s~\+(?!\()~ +~g; $case =~ s~(?