in reply to return values with system()

What exactly are you having problems with? This is quite well documented in system's documentation.

my $rv = system('perl -e "exit(123)"'); die("Unable to launch command: $!\n") if $rv == -1; die("Child died with signal ", ($rv & 127), "\n") if $rv & 127; die("Child exited with value ", ($rv >> 8), "\n") if $rv >> 8; print("Child exited successfully\n");

outputs

Child exited with value 123

Keep in mind that system("$cmd; echo $status"); will return the error code of the shell used to launch these two commands, which will be the error code of echo if nothing goes wrong.