If one string is expressed like below $str = \"5+2-1\"; I\'d like to get the calculation result from that string. How do I convert to scalar to compute this? Thanks.
If you are sure the string does not contain any malicious code you can use eval to treat the content of it as perl code.
#!/usr/bin/perl use strict; use warnings; my $string = "5+2-1"; print eval($string); #print 6