my $archive = "/some/dir/archive.tar.gz"; # Split the filename off of the directory using a regular expression my ($dir, $filename) = $archive =~ m#^(.*)/([^/]+)$#; # Switch in to the directory with the archive chdir($dir) || die "Invalid path $dir\n"; # Extract the archive using 'tar' system("tar","-xvzf",$filename);