my $string = '/MediaBox [ 0 0 614.39999 792 ]'; my ($x,$y); if ( $string =~ /^\/MediaBox \[ \S+ \S+ (\S+) (\S+) \]$/ ) { $x = $1; $y = $2; print "matched\n"; print $x . "\n"; print $y . "\n"; } else { print "no match\n"; }