chomp( my $expr = ); # and to parse it with simple split my ($left,$op,$right) = split /\s+/,$expr # next step is code of above