#! /usr/bin/perl use strict; use warnings; my $templateformat = 'wbcmsw'; my $inputexample = 'w8b8cm512swno'; if ($templateformat =~ /w(.+)b(.+)cm(.+)sw(\S*)\s*$/ ) { print "template found\n"; my $first = $1; my $second = $2; my $third = $3; my $fourth = $4; print "first=$first, second=$second, third=$third, fourth=$fourth\n"; } if ($inputexample =~ /w(.+)b(.+)cm(.+)sw(\S*)\s*$/ ) { print "input found\n"; my $first = $1; my $second = $2; my $third = $3; my $fourth = $4; print "first=$first, second=$second, third=$third, fourth=$fourth\n"; }