This function renames the file with OLDNAME to NEWNAME. Uses the system function rename( ), and so it will not rename files across file systems or volumes. If you want to copy or move a file, use the copy or move command supplied in the File::Copy module.
Following is the simple syntax for this function −
rename OLDNAME, NEWNAME
This function returns 0 on failure and 1 on success.
First create test file in /tmp directory and then use following code to change file name.
#!/usr/bin/perl -w rename("/tmp/test", "/tmp/test2") || die ( "Error in renaming" );
When above code is executed, it produces the following result −
the file gets renamed