#!/usr/bin/perl -w use strict; my $path = '\nb\v5\srcccc\ans.cpp@@\main\\'; my ($dir, $subDir, $file) = $path =~ /^\\([^\\]+)\\([^\\]+).*?(\w+\.cpp)/; print "$dir\n$subDir\n$file\n";