Function calls are a bit expensive in terms of time in Python. And yet you have a loop invariant function call to get the file name inside the loop:
fn = fileinput.filename()
Move this line above the for
loop and you should see some improvement to your Python timing. Probably not enough to beat out Perl though.