After looking at the suggested link (How can I get position of cursor in terminal?) I came up with the following horrible piece of code that sort of does what I want, although there's lots of scope for improvement:
use strict;
my $x='';
system "stty cbreak </dev/tty >/dev/tty 2>&1";
print "\e[6n";
$x=getc STDIN;
$x.=getc STDIN;
$x.=getc STDIN;
$x.=getc STDIN;
$x.=getc STDIN;
$x.=getc STDIN;
system "stty -cbreak </dev/tty >/dev/tty 2>&1";
my($n, $m)=$x=~m/(\d+)\;(\d+)/;
print "\nCursor location is $n,$m\n";
print "Bye\n";
Basically when you do an ANSI code query the reply goes to STDIN, as if you had typed it on your terminal, not STDOUT as I thought. You can use
$x=<STDIN>;
but in that case the user needs to press ENTER in order to capture the reply.
Using getc solves this but from what I read it's tricky and has portability issues. (How can I get user input without waiting for enter in Perl?, http://perldoc.perl.org/functions/getc.html).