$! stores the error message
use File::Copy; copy("nonexistant.pl","new.pl"); #Try to copy a non-existant file. print "$!\n";