Others have mentioned how to capture the output using backticks/open.
To get the name used to execute the current copy of Perl, make use of the variable
$^X (that's dollar_sign - caret - uppercase_x). See
perlvar under
$EXECUTABLE_NAME.
print "$^X\n"; # this will print realpath to perl