#!/usr/bin/perl use Data::Dumper; my ($scr, $curr_scr, %screens); open my $fh, "xdpyinfo|" or die; while (<$fh>) { $scr = $1 if m/^\s*screen\s+#(\d+):/; $curr_scr = $1 if m/^\s*default screen number:\s+(\d+)/; @{$screens{$scr}}{'x','y'} = ($1, $2) if m/^\s*dimensions:\s+(\d+)x(\d+)/; } close $fh; print "Current screen: $curr_scr\n\n"; print Dumper \%screens; #### Current screen: 2 $VAR1 = { '1' => { 'y' => '576', 'x' => '768' }, '3' => { 'y' => '576', 'x' => '768' }, '0' => { 'y' => '576', 'x' => '768' }, '2' => { 'y' => '576', 'x' => '768' } };